@jsonic/multisource 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ interface MultiSourceMeta {
4
4
  deps?: DependencyMap;
5
5
  }
6
6
  declare const NONE = "";
7
- declare type MultiSourceOptions = {
7
+ type MultiSourceOptions = {
8
8
  resolver: Resolver;
9
9
  path?: string;
10
10
  markchar?: string;
@@ -13,26 +13,26 @@ declare type MultiSourceOptions = {
13
13
  };
14
14
  implictExt?: [];
15
15
  };
16
- declare type PathSpec = {
16
+ type PathSpec = {
17
17
  kind: string;
18
18
  path?: string;
19
19
  full?: string;
20
20
  base?: string;
21
21
  abs: boolean;
22
22
  };
23
- declare type Resolution = PathSpec & {
23
+ type Resolution = PathSpec & {
24
24
  src?: string;
25
25
  val?: any;
26
26
  found: boolean;
27
27
  };
28
- declare type Resolver = (spec: PathSpec, popts: MultiSourceOptions, rule: Rule, ctx: Context, jsonic: Jsonic) => Resolution;
29
- declare type Processor = (res: Resolution, popts: MultiSourceOptions, rule: Rule, ctx: Context, jsonic: Jsonic) => void;
30
- declare type Dependency = {
28
+ type Resolver = (spec: PathSpec, popts: MultiSourceOptions, rule: Rule, ctx: Context, jsonic: Jsonic) => Resolution;
29
+ type Processor = (res: Resolution, popts: MultiSourceOptions, rule: Rule, ctx: Context, jsonic: Jsonic) => void;
30
+ type Dependency = {
31
31
  tar: string | typeof TOP;
32
32
  src: string;
33
33
  wen: number;
34
34
  };
35
- declare type DependencyMap = {
35
+ type DependencyMap = {
36
36
  [tar_full_path: string]: {
37
37
  [src_full_path: string]: Dependency;
38
38
  };
@@ -15,6 +15,7 @@ const MultiSource = (jsonic, popts) => {
15
15
  const markchar = popts.markchar;
16
16
  const resolver = popts.resolver;
17
17
  const processor = popts.processor;
18
+ const { deep } = jsonic.util;
18
19
  // Normalize implicit extensions to format `.name`.
19
20
  const implictExt = (popts.implictExt || []);
20
21
  for (let extI = 0; extI < implictExt.length; extI++) {
@@ -35,9 +36,14 @@ const MultiSource = (jsonic, popts) => {
35
36
  let dopts = {
36
37
  name: 'multisource',
37
38
  open: markchar,
39
+ rules: {
40
+ open: 'val,pair',
41
+ },
38
42
  action: function multisourceStateAction(rule, ctx) {
39
43
  var _a;
44
+ let from = rule.parent.name;
40
45
  let spec = rule.child.node;
46
+ // console.log('SRC', from, spec)
41
47
  let res = resolver(spec, popts, rule, ctx, jsonic);
42
48
  if (!res.found) {
43
49
  return (_a = rule.parent) === null || _a === void 0 ? void 0 : _a.o0.bad('multisource_not_found', { ...res });
@@ -45,9 +51,44 @@ const MultiSource = (jsonic, popts) => {
45
51
  res.kind = null == res.kind ? NONE : res.kind;
46
52
  let proc = processor[res.kind] || processor[NONE];
47
53
  proc(res, popts, rule, ctx, jsonic);
48
- rule.node = res.val;
54
+ // Handle the {@foo} case, injecting keys into parent map.
55
+ if ('pair' === from) {
56
+ if (ctx.cfg.map.merge) {
57
+ rule.parent.parent.node = ctx.cfg.map.merge(rule.parent.parent.node, res.val, rule, ctx);
58
+ }
59
+ else if (ctx.cfg.map.extend) {
60
+ rule.parent.parent.node = deep(rule.parent.parent.node, res.val);
61
+ }
62
+ else {
63
+ Object.assign(rule.parent.node, res.val);
64
+ }
65
+ }
66
+ else {
67
+ rule.node = res.val;
68
+ }
69
+ // rule.node = res.val
49
70
  return undefined;
50
71
  },
72
+ custom: (jsonic, { OPEN, name }) => {
73
+ // Handle special case of @foo first token - assume a map
74
+ jsonic.rule('val', (rs) => {
75
+ rs.open({
76
+ s: [OPEN],
77
+ c: (r) => 0 === r.d,
78
+ p: 'map',
79
+ b: 1,
80
+ n: { [name + '_top']: 1 },
81
+ });
82
+ });
83
+ jsonic.rule('map', (rs) => {
84
+ rs.open({
85
+ s: [OPEN],
86
+ c: (r) => 1 === r.d && 1 === r.n[name + '_top'],
87
+ p: 'pair',
88
+ b: 1,
89
+ });
90
+ });
91
+ },
51
92
  };
52
93
  jsonic.use(directive_1.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AAG,GAAG,GAAG,IAAI;gBACnB,CAAC,CAAC,IAAI;YACR,CAAC,CAAC,SAAS,CAAA;IAEb,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE9E,IAAI,GAAG,GAAe;QACpB,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,KAAK,EAAE,KAAK;KACb,CAAA;IAED,OAAO,GAAG,CAAA;AACZ,CAAC;AAeC,0CAAe"}
@@ -1 +1 @@
1
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JsonicMultiSource=e()}}((function(){var define,module,exports,createModuleFactory=function(e){var t;return function(o){return t||e(t={exports:{},parent:o},t.exports),t.exports}},_$multisource_1=createModuleFactory((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TOP=t.NONE=t.resolvePathSpec=t.MultiSource=void 0;const o=_$jsonic_3({});t.NONE="";const n=Symbol("TOP");t.TOP=n;const l=(e,t)=>{const o=t.markchar,n=t.resolver,l=t.processor,i=t.implictExt||[];for(let s=0;s<i.length;s++){let e=i[s];i[s]=e.startsWith(".")?e:"."+e}e.options({error:{multisource_not_found:"source not found: $path"},hint:{multisource_not_found:"The source path $path was not found."}});let r={name:"multisource",open:o,action:function(o,i){var r;let s=o.child.node,u=n(s,t,o,i,e);if(!u.found)return null===(r=o.parent)||void 0===r?void 0:r.o0.bad("multisource_not_found",{...u});u.kind=null==u.kind?"":u.kind,(l[u.kind]||l[""])(u,t,o,i,e),o.node=u.val}};e.use(_$directiveMin_4.Directive,r)};function i(e){return t=>t.val=e(t.src,t)}t.MultiSource=l;const r=i(e=>e),s=i(e=>null==e?void 0:JSON.parse(e)),u=(0,o.makeJsonicProcessor)(),c=(0,_$js_2.makeJavaScriptProcessor)();l.defaults={markchar:"@",processor:{"":r,jsonic:u,jsc:u,json:s,js:c},implictExt:["jsonic","jsc","json","js"]},t.resolvePathSpec=function(e,t,o,n){var l;let i=null===(l=t.meta)||void 0===l?void 0:l.multisource,r=n(null==i||null==i.path?e.path:i.path),s="string"==typeof o?o:null!=o.path?""+o.path:void 0,u=!(!(null==s?void 0:s.startsWith("/"))&&!(null==s?void 0:s.startsWith("\\"))),c=u?s:null!=s&&""!=s?null!=r&&""!=r?r+"/"+s:s:void 0;return{kind:null==c?"":(c.match(/\.([^.]*)$/)||["",""])[1],path:s,full:c,base:r,abs:u,found:!1}}})),_$jsonic_3=createModuleFactory((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.makeJsonicProcessor=void 0;const o=_$multisource_1({});t.makeJsonicProcessor=function(){return function(e,t,n,l,i){var r;if(null!=e.src&&null!=e.full){let t=(null===(r=l.meta)||void 0===r?void 0:r.multisource)||{},n={...l.meta||{},multisource:{...t,path:e.full}};if(e.val=i(e.src,n),t.deps){let n=t.deps,l=t.path||o.TOP;if(null!=l){let t={tar:l,src:e.full,wen:Date.now()};n[l]=n[l]||{},n[l][e.full]=t}}}}}})),_$directiveMin_4={exports:{}};(function(e){(function(){!function(t){"object"==typeof _$directiveMin_4.exports?_$directiveMin_4.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:this).JsonicDirective=t()}((function(){var e={};Object.defineProperty(e,"__esModule",{value:!0}),e.Directive=void 0;const t=(e,t)=>{let o,n=("string"==typeof t.rules?t.rules.split(/\s*,\s*/):t.rules||[]).filter(e=>""!==e),l=t.name,i=t.open,r=t.close;if("string"==typeof t.action){let n=t.action;o=t=>t.node=e.util.prop(e.options,n)}else o=t.action;let s={},u="#D_open_"+l,c="#D_close_"+l,a=e.fixed(i),d=null==r?null:e.fixed(r);if(null!=a)throw new Error("Directive open token already in use: "+i);s[u]=i,null==d&&null!=r&&(s[c]=r),e.options({fixed:{token:s},error:{[l+"_close"]:null==r?null:"directive "+l+' close "'+r+'" without open "'+i+'"'},hint:{[l+"_close"]:null==r?null:`\nThe ${l} directive must start with the characters "${i}" and end\nwith the characters "${r}". The end characters "${r}" may not\nappear without the start characters "${i}" appearing first:\n"${i}...${r}".\n`}});let f=e.token.CA;a=e.fixed(i),d=null==r?null:e.fixed(r),n.forEach(t=>{e.rule(t,e=>(e.open({s:[a],p:l,n:{dr:1}}),null!=r&&(e.open([{s:[d],c:{n:{dr:0}},e:(e,t)=>t.t0.bad(l+"_close")},{s:[d],b:1}]),e.close({s:[d],b:1})),e))}),e.rule(l,e=>e.clear().bo(e=>{e.node={}}).open([{p:"val",n:null==r?{}:{pk:-1,il:0}}]).bc((function(e,t){let n=o.call(this,e,t);if(null==n?void 0:n.isToken)return n})).close(null!=r?[{s:[d]},{s:[f,d]}]:[]))};return e.Directive=t,t.defaults={rules:"val,pair,elem"},e}))}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),_$directiveMin_4=_$directiveMin_4.exports;var _$js_2={};function makeJavaScriptProcessor(e){const t=t=>{t.val=evaluate(t,e)};return t.opts=e,t}function evaluate(res,opts){let out=void 0;if(!0!==(null==opts?void 0:opts.evalOnly))out=require(res.full);else{let exports=null,module={exports:exports};eval(res.src),out=module.exports}return out}return Object.defineProperty(_$js_2,"__esModule",{value:!0}),_$js_2.makeJavaScriptProcessor=void 0,_$js_2.makeJavaScriptProcessor=makeJavaScriptProcessor,_$multisource_1(),_$multisource_1}));
1
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).JsonicMultiSource=e()}}((function(){var define,module,exports,createModuleFactory=function(e){var t;return function(n){return t||e(t={exports:{},parent:n},t.exports),t.exports}},_$multisource_1=createModuleFactory((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TOP=t.NONE=t.resolvePathSpec=t.MultiSource=void 0;const n=_$jsonic_3({});t.NONE="";const o=Symbol("TOP");t.TOP=o;const l=(e,t)=>{const n=t.markchar,o=t.resolver,l=t.processor,{deep:r}=e.util,i=t.implictExt||[];for(let u=0;u<i.length;u++){let e=i[u];i[u]=e.startsWith(".")?e:"."+e}e.options({error:{multisource_not_found:"source not found: $path"},hint:{multisource_not_found:"The source path $path was not found."}});let s={name:"multisource",open:n,rules:{open:"val,pair"},action:function(n,i){var s;let u=n.parent.name,a=n.child.node,c=o(a,t,n,i,e);if(!c.found)return null===(s=n.parent)||void 0===s?void 0:s.o0.bad("multisource_not_found",{...c});c.kind=null==c.kind?"":c.kind,(l[c.kind]||l[""])(c,t,n,i,e),"pair"===u?i.cfg.map.merge?n.parent.parent.node=i.cfg.map.merge(n.parent.parent.node,c.val,n,i):i.cfg.map.extend?n.parent.parent.node=r(n.parent.parent.node,c.val):Object.assign(n.parent.node,c.val):n.node=c.val},custom:(e,{OPEN:t,name:n})=>{e.rule("val",e=>{e.open({s:[t],c:e=>0===e.d,p:"map",b:1,n:{[n+"_top"]:1}})}),e.rule("map",e=>{e.open({s:[t],c:e=>1===e.d&&1===e.n[n+"_top"],p:"pair",b:1})})}};e.use(_$directiveMin_4.Directive,s)};function r(e){return t=>t.val=e(t.src,t)}t.MultiSource=l;const i=r(e=>e),s=r(e=>null==e?void 0:JSON.parse(e)),u=(0,n.makeJsonicProcessor)(),a=(0,_$js_2.makeJavaScriptProcessor)();l.defaults={markchar:"@",processor:{"":i,jsonic:u,jsc:u,json:s,js:a},implictExt:["jsonic","jsc","json","js"]},t.resolvePathSpec=function(e,t,n,o){var l;let r=null===(l=t.meta)||void 0===l?void 0:l.multisource,i=o(null==r||null==r.path?e.path:r.path),s="string"==typeof n?n:null!=n.path?""+n.path:void 0,u=!(!(null==s?void 0:s.startsWith("/"))&&!(null==s?void 0:s.startsWith("\\"))),a=u?s:null!=s&&""!=s?null!=i&&""!=i?i+"/"+s:s:void 0;return{kind:null==a?"":(a.match(/\.([^.]*)$/)||["",""])[1],path:s,full:a,base:i,abs:u,found:!1}}})),_$jsonic_3=createModuleFactory((function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.makeJsonicProcessor=void 0;const n=_$multisource_1({});t.makeJsonicProcessor=function(){return function(e,t,o,l,r){var i;if(null!=e.src&&null!=e.full){let t=(null===(i=l.meta)||void 0===i?void 0:i.multisource)||{},o={...l.meta||{},multisource:{...t,path:e.full}};if(e.val=r(e.src,o),t.deps){let o=t.deps,l=t.path||n.TOP;if(null!=l){let t={tar:l,src:e.full,wen:Date.now()};o[l]=o[l]||{},o[l][e.full]=t}}}}}})),_$directiveMin_4={exports:{}};(function(e){(function(){!function(t){"object"==typeof _$directiveMin_4.exports?_$directiveMin_4.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:this).JsonicDirective=t()}((function(){var e={};Object.defineProperty(e,"__esModule",{value:!0}),e.Directive=void 0;const t=e=>("string"==typeof e?e.split(/\s*,\s*/):e||[]).filter(e=>null!=e&&""!==e),n=(e,n)=>{var o,l;let r,i={open:t(null===(o=null==n?void 0:n.rules)||void 0===o?void 0:o.open),close:t(null===(l=null==n?void 0:n.rules)||void 0===l?void 0:l.close)},s=n.name,u=n.open,a=n.close,c=n.custom;if("string"==typeof n.action){let t=n.action;r=n=>n.node=e.util.prop(e.options,t)}else r=n.action;let d={},p="#OD_"+s,f="#CD_"+s,v=e.fixed(u),_=null==a?null:e.fixed(a);if(null!=v)throw new Error("Directive open token already in use: "+u);d[p]=u,null==_&&null!=a&&(d[f]=a),e.options({fixed:{token:d},error:{[s+"_close"]:null==a?null:"directive "+s+' close "'+a+'" without open "'+u+'"'},hint:{[s+"_close"]:null==a?null:`\nThe ${s} directive must start with the characters "${u}" and end\nwith the characters "${a}". The end characters "${a}" may not\nappear without the start characters "${u}" appearing first:\n"${u}...${a}".\n`}});let m=e.token.CA;v=e.fixed(u),_=null==a?null:e.fixed(a),i.open.forEach(t=>{e.rule(t,e=>(e.open({s:[v],p:s,n:{["dr_"+s]:1},g:"start"}),null!=a&&(e.open({s:[v,_],b:1,p:s,n:{["dr_"+s]:1},g:"start,end"}),e.close({s:[_],b:1,g:"end"})),e))}),null!=a&&i.close.forEach(t=>{e.rule(t,e=>{e.close([{s:[_],c:e=>1===e.n["dr_"+s],b:1,g:"end"},{s:[m,_],c:e=>1===e.n["dr_"+s],b:1,g:"end,comma"}])})}),e.rule(s,e=>e.clear().bo(e=>{e.node={}}).open([null!=a?{s:[_],b:1}:null,{p:"val",n:null==a?{dlist:1,dmap:1}:{dlist:0,dmap:0}}]).bc((function(e,t,n,o){let l=r.call(this,e,t,n,o);if(null==l?void 0:l.isToken)return l})).close(null!=a?[{s:[_]},{s:[m,_]}]:[])),c&&c(e,{OPEN:v,CLOSE:_,name:s})};return e.Directive=n,n.defaults={rules:{open:"val",close:"list,elem,map,pair"}},e}))}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),_$directiveMin_4=_$directiveMin_4.exports;var _$js_2={};function makeJavaScriptProcessor(e){const t=t=>{t.val=evaluate(t,e)};return t.opts=e,t}function evaluate(res,opts){let out;if(!0!==(null==opts?void 0:opts.evalOnly))out=require(res.full);else{let exports=null,module={exports:exports};eval(res.src),out=module.exports}return out}return Object.defineProperty(_$js_2,"__esModule",{value:!0}),_$js_2.makeJavaScriptProcessor=void 0,_$js_2.makeJavaScriptProcessor=makeJavaScriptProcessor,_$multisource_1(),_$multisource_1}));
@@ -1,4 +1,4 @@
1
1
  import { Resolver } from '../multisource';
2
- declare type PathFinder = (spec: any) => string;
2
+ type PathFinder = (spec: any) => string;
3
3
  declare function makeFileResolver(pathfinder?: PathFinder): Resolver;
4
4
  export { makeFileResolver, };
package/jest.config.js CHANGED
@@ -1,9 +1,9 @@
1
- /** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
2
1
  module.exports = {
3
- transform: {
4
- "^.+\\.tsx?$": "esbuild-jest"
5
- },
2
+ coveragePathIgnorePatterns: ['test'],
6
3
  testEnvironment: 'node',
7
4
  testMatch: ['**/test/**/*.test.ts'],
8
5
  watchPathIgnorePatterns: ['.*.js$'],
6
+ transform: {
7
+ "^.+\\.tsx?$": "es-jest"
8
+ },
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonic/multisource",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "",
5
5
  "main": "dist/multisource.js",
6
6
  "type": "commonjs",
@@ -41,18 +41,19 @@
41
41
  "dist"
42
42
  ],
43
43
  "devDependencies": {
44
- "@types/jest": "^27.5.1",
44
+ "@types/jest": "^29.2.4",
45
45
  "browserify": "^17.0.0",
46
- "esbuild": "^0.14.42",
46
+ "esbuild": "^0.16.12",
47
47
  "esbuild-jest": "^0.5.0",
48
- "jest": "^28.1.0",
49
- "@jsonic/jsonic-next": "2.0.2",
50
- "prettier": "^2.6.2",
51
- "tinyify": "^3.0.0",
52
- "ts-jest": "^28.0.3",
53
- "typescript": "^4.7.2"
48
+ "jest": "^29.3.1",
49
+ "prettier": "^2.8.1",
50
+ "tinyify": "^4.0.0",
51
+ "es-jest": "^2.1.0",
52
+ "typescript": "^4.9.4"
54
53
  },
55
- "dependencies": {
56
- "@jsonic/directive": "^0.7.0"
57
- }
54
+ "peerDependencies": {
55
+ "@jsonic/jsonic-next": ">=2.5.4",
56
+ "@jsonic/directive": ">=0.9.0"
57
+ },
58
+ "dependencies": {}
58
59
  }
@@ -81,6 +81,8 @@ const MultiSource: Plugin = (jsonic: Jsonic, popts: MultiSourceOptions) => {
81
81
  const resolver = popts.resolver as Resolver
82
82
  const processor = popts.processor as { [kind: string]: Processor }
83
83
 
84
+ const { deep } = jsonic.util
85
+
84
86
  // Normalize implicit extensions to format `.name`.
85
87
  const implictExt = (popts.implictExt || []) as string[]
86
88
  for (let extI = 0; extI < implictExt.length; extI++) {
@@ -103,8 +105,13 @@ const MultiSource: Plugin = (jsonic: Jsonic, popts: MultiSourceOptions) => {
103
105
  let dopts: DirectiveOptions = {
104
106
  name: 'multisource',
105
107
  open: markchar,
108
+ rules: {
109
+ open: 'val,pair',
110
+ },
106
111
  action: function multisourceStateAction(rule: Rule, ctx: Context) {
112
+ let from = rule.parent.name
107
113
  let spec = rule.child.node
114
+ // console.log('SRC', from, spec)
108
115
 
109
116
  let res = resolver(spec, popts, rule, ctx, jsonic)
110
117
  if (!res.found) {
@@ -116,10 +123,49 @@ const MultiSource: Plugin = (jsonic: Jsonic, popts: MultiSourceOptions) => {
116
123
  let proc = processor[res.kind] || processor[NONE]
117
124
  proc(res, popts, rule, ctx, jsonic)
118
125
 
119
- rule.node = res.val
126
+ // Handle the {@foo} case, injecting keys into parent map.
127
+ if ('pair' === from) {
128
+ if (ctx.cfg.map.merge) {
129
+ rule.parent.parent.node = ctx.cfg.map.merge(
130
+ rule.parent.parent.node,
131
+ res.val,
132
+ rule,
133
+ ctx
134
+ )
135
+ } else if (ctx.cfg.map.extend) {
136
+ rule.parent.parent.node = deep(rule.parent.parent.node, res.val)
137
+ } else {
138
+ Object.assign(rule.parent.node, res.val)
139
+ }
140
+ } else {
141
+ rule.node = res.val
142
+ }
143
+
144
+ // rule.node = res.val
120
145
 
121
146
  return undefined
122
147
  },
148
+ custom: (jsonic: Jsonic, { OPEN, name }: any) => {
149
+ // Handle special case of @foo first token - assume a map
150
+ jsonic.rule('val', (rs) => {
151
+ rs.open({
152
+ s: [OPEN],
153
+ c: (r) => 0 === r.d,
154
+ p: 'map',
155
+ b: 1,
156
+ n: { [name + '_top']: 1 },
157
+ })
158
+ })
159
+
160
+ jsonic.rule('map', (rs) => {
161
+ rs.open({
162
+ s: [OPEN],
163
+ c: (r) => 1 === r.d && 1 === r.n[name + '_top'],
164
+ p: 'pair',
165
+ b: 1,
166
+ })
167
+ })
168
+ },
123
169
  }
124
170
  jsonic.use(Directive, dopts)
125
171
  }