babel-plugin-wallace 0.0.2 → 0.0.6

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.
Files changed (120) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/ast-helpers.d.ts +10 -0
  3. package/dist/ast-helpers.js +52 -0
  4. package/dist/ast-helpers.js.map +1 -0
  5. package/dist/babel-types.d.ts +4 -0
  6. package/dist/babel-types.js +3 -0
  7. package/dist/babel-types.js.map +1 -0
  8. package/dist/config.d.ts +14 -0
  9. package/dist/config.js +47 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/consolidation/ComponentDefinitionData.d.ts +29 -0
  12. package/dist/consolidation/ComponentDefinitionData.js +82 -0
  13. package/dist/consolidation/ComponentDefinitionData.js.map +1 -0
  14. package/dist/consolidation/consolidateComponent.d.ts +6 -0
  15. package/dist/consolidation/consolidateComponent.js +41 -0
  16. package/dist/consolidation/consolidateComponent.js.map +1 -0
  17. package/dist/consolidation/index.d.ts +2 -0
  18. package/dist/consolidation/index.js +8 -0
  19. package/dist/consolidation/index.js.map +1 -0
  20. package/dist/consolidation/processNodes.d.ts +3 -0
  21. package/dist/consolidation/processNodes.js +202 -0
  22. package/dist/consolidation/processNodes.js.map +1 -0
  23. package/dist/consolidation/types.d.ts +15 -0
  24. package/dist/consolidation/types.js +3 -0
  25. package/dist/consolidation/types.js.map +1 -0
  26. package/dist/consolidation/utils.d.ts +21 -0
  27. package/dist/consolidation/utils.js +91 -0
  28. package/dist/consolidation/utils.js.map +1 -0
  29. package/dist/consolidation/visibility.d.ts +5 -0
  30. package/dist/consolidation/visibility.js +43 -0
  31. package/dist/consolidation/visibility.js.map +1 -0
  32. package/dist/constants.d.ts +31 -0
  33. package/dist/constants.js +40 -0
  34. package/dist/constants.js.map +1 -0
  35. package/dist/contexts/handlers.d.ts +18 -0
  36. package/dist/contexts/handlers.js +152 -0
  37. package/dist/contexts/handlers.js.map +1 -0
  38. package/dist/contexts/index.d.ts +2 -0
  39. package/dist/contexts/index.js +6 -0
  40. package/dist/contexts/index.js.map +1 -0
  41. package/dist/contexts/parameters.d.ts +8 -0
  42. package/dist/contexts/parameters.js +114 -0
  43. package/dist/contexts/parameters.js.map +1 -0
  44. package/dist/directives.d.ts +8 -0
  45. package/dist/directives.js +193 -0
  46. package/dist/directives.js.map +1 -0
  47. package/dist/errors.d.ts +34 -0
  48. package/dist/errors.js +47 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/helpers.d.ts +4 -0
  51. package/dist/helpers.js +35 -0
  52. package/dist/helpers.js.map +1 -0
  53. package/dist/index.d.ts +10 -0
  54. package/dist/index.js +34 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/models/component.d.ts +25 -0
  57. package/dist/models/component.js +114 -0
  58. package/dist/models/component.js.map +1 -0
  59. package/dist/models/directive.d.ts +13 -0
  60. package/dist/models/directive.js +8 -0
  61. package/dist/models/directive.js.map +1 -0
  62. package/dist/models/index.d.ts +5 -0
  63. package/dist/models/index.js +15 -0
  64. package/dist/models/index.js.map +1 -0
  65. package/dist/models/module.d.ts +12 -0
  66. package/dist/models/module.js +40 -0
  67. package/dist/models/module.js.map +1 -0
  68. package/dist/models/node.d.ts +107 -0
  69. package/dist/models/node.js +327 -0
  70. package/dist/models/node.js.map +1 -0
  71. package/dist/utils.d.ts +13 -0
  72. package/dist/utils.js +66 -0
  73. package/dist/utils.js.map +1 -0
  74. package/dist/visitors/attribute.d.ts +10 -0
  75. package/dist/visitors/attribute.js +82 -0
  76. package/dist/visitors/attribute.js.map +1 -0
  77. package/dist/visitors/jsx.d.ts +13 -0
  78. package/dist/visitors/jsx.js +61 -0
  79. package/dist/visitors/jsx.js.map +1 -0
  80. package/dist/visitors/program.d.ts +12 -0
  81. package/dist/visitors/program.js +26 -0
  82. package/dist/visitors/program.js.map +1 -0
  83. package/dist/writers/define-component.d.ts +7 -0
  84. package/dist/writers/define-component.js +101 -0
  85. package/dist/writers/define-component.js.map +1 -0
  86. package/dist/writers/index.d.ts +1 -0
  87. package/dist/writers/index.js +7 -0
  88. package/dist/writers/index.js.map +1 -0
  89. package/package.json +20 -10
  90. package/README.md +0 -3
  91. package/lib/_config/directives.js +0 -356
  92. package/lib/_config/index.js +0 -2
  93. package/lib/_config/loader.js +0 -43
  94. package/lib/_config/parse_directives.js +0 -63
  95. package/lib/config.js +0 -263
  96. package/lib/convert.js +0 -27
  97. package/lib/definitions/constants.js +0 -73
  98. package/lib/definitions/node_data.js +0 -183
  99. package/lib/definitions/watcher.js +0 -26
  100. package/lib/generate/code_generator.js +0 -333
  101. package/lib/generate/statement_builders.js +0 -130
  102. package/lib/help-system/browser-code.js +0 -50
  103. package/lib/help-system/entry.js +0 -92
  104. package/lib/help-system/error-display.js +0 -20
  105. package/lib/help-system/styles.css +0 -25
  106. package/lib/import-checker.js +0 -35
  107. package/lib/index.js +0 -47
  108. package/lib/jsx/component_dom.js +0 -40
  109. package/lib/jsx/contexts.js +0 -121
  110. package/lib/jsx/extract.js +0 -214
  111. package/lib/jsx/parse.js +0 -98
  112. package/lib/parse/component_templates.js +0 -44
  113. package/lib/parse/inline_directives.js +0 -318
  114. package/lib/parse/parse_node.js +0 -73
  115. package/lib/polyfills.js +0 -10
  116. package/lib/utils/babel.js +0 -100
  117. package/lib/utils/dom.js +0 -174
  118. package/lib/utils/misc.js +0 -152
  119. package/lib_old/handlers.js +0 -52
  120. package/lib_old/index.js +0 -145
@@ -1,43 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const {directives} = require('./directives');
4
-
5
-
6
- const config = {
7
- options: {
8
- inlineDelimiters: ['{', '}']
9
- },
10
- aliases: {
11
- '': 'watch'
12
- },
13
- directives: directives
14
- }
15
-
16
- // Use custom config file if there is one.
17
- const customConfigFile = path.join(process.cwd(), 'wallace.config.js')
18
-
19
-
20
- if (fs.existsSync(customConfigFile)) {
21
-
22
- var customConfig = require(customConfigFile)
23
- if (customConfig.directives) {
24
- Object.assign(config.directives, customConfig.directives)
25
- }
26
- // TODO: check options are valid.
27
- if (customConfig.options) {
28
- Object.assign(config.options, customConfig.options)
29
- }
30
- }
31
-
32
- for (const key of Object.keys(config.directives)) {
33
- if (key.toLowerCase().startsWith("on") && key !== "on") {
34
- throw new Error(`Directive "${key}" may not start with 'on' as this is reserved for event handlers.`)
35
- }
36
- }
37
-
38
- // const directives = config.directives
39
- // for (const [key, value] of Object.entries(config.aliases)) {
40
- // directives[':' + key] = directives[':' + value]
41
- // }
42
-
43
- module.exports = {config}
@@ -1,63 +0,0 @@
1
- /**
2
- * This module deals with parsing the directives in the config file,
3
- * and helping them parse arguments.
4
- */
5
-
6
- const {isFunc, isUnd, splitTrim} = require('../utils/misc')
7
-
8
- /**
9
- * Used internally to
10
- *
11
- * @param {string} directiveName
12
- * @param {*} directive
13
- * @param {*} attVal
14
- */
15
- const processDirective = (nodeData, directiveName, directive, attVal) => {
16
- if (!isFunc(directive.handle)) {
17
- throw new Error('handle must be a function')
18
- }
19
- let args = attVal
20
- if (directive.hasOwnProperty('params')) {
21
- let params = splitTrim(directive.params, ',')
22
- args = parseDirectiveArguments(params, attVal)
23
- directive.handle.apply(nodeData, args)
24
- } else {
25
- directive.handle.apply(nodeData, [args])
26
- }
27
- }
28
-
29
- /**
30
- * Return array of args based on definitions
31
- *
32
- * @param {Array} params The parameters as strings
33
- * @param {String} attVal The raw attribute value.
34
- */
35
- const parseDirectiveArguments = (params, attVal) => {
36
- const args = []
37
- const chunks = splitTrim(attVal, '|')
38
- for (let i=0, il=params.length; i<il; i++) {
39
- let param = params[i]
40
- let raw = chunks[i]
41
- let value = parseArgValue(param, raw, i)
42
- args.push(value)
43
- }
44
- return args
45
- }
46
-
47
- const parseArgValue = (param, raw, i) => {
48
- if ((!param.endsWith('?')) && (isUnd(raw))) {
49
- throw new Error(`Argument ${param} is required`)
50
- }
51
- return raw
52
- }
53
-
54
- const extractDocumentation = (name, directive) => {
55
- return {
56
- name: name,
57
- params: directive.params
58
- }
59
- }
60
-
61
-
62
-
63
- module.exports = {processDirective, extractDocumentation}
package/lib/config.js DELETED
@@ -1,263 +0,0 @@
1
- const {alwaysUpdate, componentRefVariable} = require('./definitions/constants')
2
-
3
- /**
4
- * Constructor for the single config instance.
5
- */
6
- function Config(directives) {
7
- this.directives = {}
8
- for (const [key, value] of Object.entries(directives)) {
9
- this.directives[key] = applyDirectiveDefaults(value)
10
- }
11
- }
12
-
13
- /**
14
- * This allows the user to configure the single config instance.
15
- */
16
- Config.prototype.configure = function(customConfig) {
17
- if (customConfig.directives) {
18
- // TODO: validate case, format etc...
19
- Object.assign(this.directives, customConfig.directives)
20
- }
21
- }
22
-
23
- // Move to types
24
- const callData = {
25
- value: "str", // if type str
26
- args: "str", // if type expr
27
- qualifier: "str|undefined", // foo:qualifier
28
- }
29
-
30
-
31
- const schema = {
32
- help: "str",
33
- allow: "str|expr|null",
34
- qualifier: "yes|no|optional",
35
- handle: "function(nodeData, callData)",
36
- args: "array", // only if type "expr"
37
- argSets: "array", // in case it allows multiple args
38
- }
39
-
40
- const applyDirectiveDefaults = (directive) => {
41
- const defaults = {
42
- allow: "expr",
43
- qualifier: "no",
44
- handle: "function(nodeData, callData)"
45
- }
46
- Object.assign(defaults, directive)
47
- return defaults
48
- }
49
-
50
-
51
- const directives = {
52
- att: {
53
- help: `
54
- Sets an HTML attribute on the element:
55
-
56
- /h <div _att:hidden="x > 3"></div>
57
- `,
58
- allow: "expr",
59
- qualifier: "yes",
60
- handle: function(nodeData, attInfo) {
61
- nodeData.addWatch(attInfo.args[0], attInfo.args[1], `@${attInfo.qualifier}`)
62
- }
63
-
64
- },
65
- call: {
66
- help: `
67
- Watch a value and call a wrapper method if it changes.
68
-
69
- /h <div _call:method={watch, tranform}></div>
70
-
71
- Variables for watch: c, p
72
- Variables for callback: c, p, n, o, w
73
- `,
74
- allow: "expr",
75
- qualifier: "yes",
76
- handle: function(nodeData, attInfo) {
77
- nodeData.addWatch(attInfo.args[0], attInfo.args[1], attInfo.qualifier)
78
- }
79
- },
80
- // checked: {
81
- // help: `
82
- // Sets the "checked" status of the element:
83
-
84
- // /h <input _checked={c.active} type="checkbox"/>
85
- // `,
86
- // allow: "expr",
87
- // handle: function(nodeData, attInfo) {
88
- // nodeData.addWatch(attInfo.args[0], undefined, 'checked')
89
- // }
90
- // },
91
- // disabled: {
92
- // help: `
93
- // Sets the "disabled" status of the element:
94
-
95
- // /h <button _disabled={!c.active}>...</button>
96
- // `,
97
- // allowedTypes: "expr",
98
- // handle: function(nodeData, attInfo) {
99
- // nodeData.addWatch(attInfo.args[0], undefined, 'disabled')
100
- // }
101
- // },
102
- // class: {
103
- // help: `
104
- // Sets the "checked" status of the element:
105
-
106
- // /h <input _checked={c.active} type="checkbox"/>
107
- // `,
108
- // allow: "expr",
109
- // handle: function(nodeData, attInfo) {
110
- // nodeData.addWatch(attInfo.args[0], undefined, 'className')
111
- // }
112
- // },
113
- el: {
114
- help: `
115
- Gives the wrapper for this element a name so it can be accessed later:
116
-
117
- /h <div el:user></div>
118
-
119
- /j c.el.user.text("Wallace")
120
- `,
121
- allow: "null",
122
- qualifier: "yes",
123
- handle: function(nodeData, attInfo) {
124
- nodeData.saveAs = attInfo.qualifier
125
- }
126
- },
127
- repeat: {
128
- help: `
129
- Repeats a nested component:
130
-
131
- /h <div>
132
- /h <Child repeat={c.items|id} />
133
- /h </div>
134
-
135
- `,
136
- allow: "expr",
137
- handle: function(nodeData, attInfo) {
138
- const parent = nodeData.parentNodeData
139
- if (parent === undefined) {
140
- // TODO: throw better error, and assert parent has no other children.
141
- throw Error("For must be used under a parent.")
142
- }
143
- const componentDef = nodeData.nestedClass
144
- const data = attInfo.args[0]
145
- const key = attInfo.args[1]
146
- parent.chainedCalls.push(`pool(${parent.buildPoolInit(componentDef, key)})`)
147
- parent.addWatch(alwaysUpdate, data, 'items', componentRefVariable)
148
- nodeData.isRepeat = true
149
- }
150
- },
151
- hidden: {
152
- help: `
153
- Hides an element:
154
-
155
- /h <div hidden={x > 10}></div>
156
-
157
- Available args are: c, p
158
- `,
159
- allow: "expr",
160
- handle: function(nodeData, attInfo) {
161
- nodeData.shieldQuery = attInfo.args[0]
162
- }
163
- },
164
- on: {
165
- help: `
166
- Creates an event handler:
167
-
168
- /h <div on:click={alert('hello')}></div>
169
-
170
- Available args are: w, e
171
- `,
172
- allow: "expr",
173
- qualifier: "yes",
174
- handle: function(nodeData, attInfo) {
175
- nodeData.addEventListener(attInfo.qualifier, attInfo.args[0])
176
- }
177
- },
178
-
179
- // TODO: change this because we may use a special wrapper?
180
- pool: {
181
- help: `
182
- Specify a pool object for repeat items:
183
-
184
- /h <div pool={poolObject}></div>
185
-
186
- `,
187
- allow: "expr",
188
- handle: function(nodeData, attInfo) {
189
- nodeData.chainedCalls.push(`pool(${attInfo.args[0]})`)
190
- }
191
- },
192
- props: {
193
- help: `
194
- Specify props for a nested component:
195
-
196
- /h <NestedComponent props={{foo: 'bar'}} />
197
-
198
- `,
199
- allow: "expr",
200
- handle: function(nodeData, attInfo) {
201
- nodeData.props = nodeData.expandProps(attInfo.args[0])
202
- }
203
- },
204
- show: {
205
- help: `
206
- Shows an element:
207
-
208
- /h <div show={x > 10}></div>
209
-
210
- Variables are: c, p
211
- `,
212
- allow: "expr",
213
- handle: function(nodeData, attInfo) {
214
- nodeData.shieldQuery = attInfo.args[0]
215
- nodeData.reverseShield = 1
216
- }
217
- },
218
- style: {
219
- help: `
220
- Sets the style directive:
221
-
222
- /h <div style:color={p.color}></div>
223
-
224
- Variables are: c, p
225
- `,
226
- allow: "expr",
227
- qualifier: "yes",
228
- handle: function(nodeData, attInfo) {
229
- nodeData.addWatch(attInfo.args[0], undefined, 'style', `'${attInfo.qualifier}'`)
230
- }
231
- },
232
- watch: {
233
- help: `
234
- Watch a value and call
235
-
236
- /h <div watch={watch, callback}></div>
237
-
238
- Variables for watch: c, p
239
- Variables for callback: c, p, n, o, w
240
- `,
241
- allow: "expr",
242
- handle: function(nodeData, attInfo) {
243
- nodeData.addWatch(...attInfo.args)
244
- }
245
- },
246
- wrapper: {
247
- help: `
248
- Specify an alternative wrapper class:
249
-
250
- /h <div wrapper={MyCustomWrapper}></div>
251
-
252
- Available args are: c, p
253
- `,
254
- allow: "expr",
255
- handle: function(nodeData, attInfo) {
256
- nodeData.customWrapperClass = attInfo.args[0]
257
- }
258
- },
259
- }
260
-
261
- const config = new Config(directives)
262
-
263
- module.exports = {config}
package/lib/convert.js DELETED
@@ -1,27 +0,0 @@
1
- const { parseJSX } = require('./jsx/parse.js')
2
- const { CodeGenerator } = require('./generate/code_generator')
3
- const {allVariableLetters} = require('./definitions/constants')
4
-
5
- const generatecomponentDefinitionArgs = (componentDefinition) => {
6
-
7
- const {componentName, html, dynamicNodes} = componentDefinition
8
- const generator = new CodeGenerator(componentName, html)
9
- dynamicNodes.forEach(node => {
10
- generator.processNodeWithDirectives(node)
11
- })
12
- return generator.buildStatements()
13
- }
14
-
15
-
16
- const convertJSX = (path, componentName) => {
17
- const parsedData = parseJSX(path, componentName)
18
- for (const letter of allVariableLetters) {
19
- delete path.scope.globals[letter]
20
- }
21
- return generatecomponentDefinitionArgs(parsedData)
22
- }
23
-
24
-
25
- module.exports = {
26
- convertJSX
27
- }
@@ -1,73 +0,0 @@
1
- const EOL = require('os').EOL
2
- const wallaceDefs = ['__html__', '__clone__', '__stubs__']
3
-
4
- /**
5
- * The character on which to split attributes and inlines
6
- */
7
- const splitter = '|'
8
-
9
- /**
10
- * The args string for watch callbacks.
11
- */
12
- const watchArgs = '(n, o)'
13
-
14
- /**
15
- * The parameters for various callback functions.
16
- * The letters mean:
17
- *
18
- * newValue
19
- * oldValue
20
- * wrapper
21
- * props
22
- * component
23
- * event
24
- */
25
- const allVariableLetters = ['n', 'o', 'w', 'p', 'c', 'e']
26
- const watchCallbackArgsWithValue = 'n, o, w, p, c'
27
- const watchCallbackArgsWithoutValue = 'w, p, c'
28
- const lookupCallbackArgs = 'c, p'
29
- const propsCallbackArgs = 'c, p'
30
- const eventCallbackArgs = 'w, e'
31
-
32
- // The component itself still needs to see this as '*'
33
- const lookupAlwaysUpdate = "*";
34
- const alwaysUpdate = 'A';
35
- const neverUpdate = 'N';
36
-
37
- /**
38
- * The name of the arg representing the component in the buildComponent method.
39
- */
40
- const componentRefInBuild = 'component'
41
- const callableWatchArgs = `${componentRefInBuild}, props`
42
- const componentRefVariable = 'c'; // The variable name by which the component will be known.
43
-
44
- function FrameworkError (msg) {
45
- this.msg = msg
46
- }
47
-
48
- function RequestsHelp (topic) {
49
- this.topic = topic
50
- }
51
-
52
- FrameworkError.prototype = new Error();
53
-
54
- module.exports = {
55
- allVariableLetters,
56
- EOL,
57
- callableWatchArgs,
58
- componentRefVariable,
59
- alwaysUpdate,
60
- neverUpdate,
61
- lookupAlwaysUpdate,
62
- FrameworkError,
63
- eventCallbackArgs,
64
- wallaceDefs,
65
- splitter,
66
- componentRefInBuild,
67
- lookupCallbackArgs,
68
- propsCallbackArgs,
69
- RequestsHelp,
70
- watchArgs,
71
- watchCallbackArgsWithValue,
72
- watchCallbackArgsWithoutValue
73
- }
@@ -1,183 +0,0 @@
1
- const {eventCallbackArgs, componentRefInBuild} = require('./constants')
2
- const {replaceArgs} = require('../utils/misc')
3
- const {FrameworkError} = require('./constants')
4
- const {Watcher} = require('./watcher')
5
-
6
- /**
7
- * A NodeData object is created for every HTML node with directives.
8
- * Its data will be used to generate statements on the component.
9
- * It exposes methods which enable directives to set that data.
10
- * It also contains the directive syntax rules (expansion etc...) which we may
11
- * want to use in directives in config.
12
- */
13
- // ALternative names: DynamicNode, WrappedNode, SpecialNode
14
- class NodeData {
15
- constructor(componentName, path, parentNodeData, nodeTreeAddress) {
16
- this.componentName = componentName
17
- this.path = path
18
- this.parentNodeData = parentNodeData
19
- this.nodeTreeAddress = nodeTreeAddress
20
- this.processAsStub = false
21
- this.stubName = undefined
22
- this.nestedClass = undefined
23
- this.isRepeat = false
24
- this.saveAs = undefined
25
- this.customWrapperClass = undefined
26
- this.customWrapperArgs = undefined
27
- this.props = undefined
28
- this.shieldQuery = undefined
29
- this.reverseShield = 0
30
- this.replaceWith = undefined
31
- this.chainedCalls = []
32
- this.watches = []
33
- this.beforeSave = []
34
- this.afterSave = []
35
- this.additionalLookups = {}
36
- this.seq = 0
37
- }
38
- isDynamic() {
39
- return (
40
- this.watches.length > 0 || this.chainedCalls.length > 0 || this.beforeSave.length > 0 || this.afterSave.length > 0
41
- || this.additionalLookups.length > 0 || this.props || this.shieldQuery || this.replaceWith || this.saveAs ||
42
- this.customWrapperClass || this.customWrapperArgs
43
- )
44
- }
45
- /**
46
- * Creates a watch on this node.
47
- *
48
- * @param {string} watch - the field or function to watch.
49
- * @param {string} [converter] - the value to pass to method, or free function call if no wrapperMethod supplied.
50
- * @param {string} [wrapperMethod] - the method on the wrapper (may use "@attName" syntax).
51
- * @param {string} [extraArg] - And extra argument to pass to the wrapperMethod
52
- * @param {string} [lookup] - name of the lookup to use.
53
- */
54
- addWatch(watch, converter, wrapperMethod, extraArg, lookup) {
55
- this.watches.push(new Watcher(
56
- this.expandValueSlot(watch), this.expandValueSlot(converter), wrapperMethod, extraArg, lookup
57
- ))
58
- }
59
- /**
60
- * Creates an event listener on this node.
61
- * Slot will be expanded.
62
- *
63
- * @param {string} event
64
- * @param {string} slot
65
- */
66
- addEventListener(event, slot) {
67
- const callback = this.buildEventListenerCallback(slot)
68
- // TODO: don't create a wapper unless it is needed.
69
- this.chainedCalls.push(`on('${event.toLowerCase()}', ${callback})`)
70
- }
71
- /**
72
- * Builds the callback function for an event handler.
73
- * Replaces c & p arguments with variables from the outer scope
74
- * if present as these are not provided by the wrapper.
75
- *
76
- * @param {string} slot
77
- */
78
- buildEventListenerCallback(slot) {
79
- // TODO: change this to detect which vars are used, and use constants.
80
- const vars = "var c = component, p = component.props"
81
- const body = [vars, slot].join(";")
82
- return `function(${eventCallbackArgs}) {${body}}`
83
- }
84
- /**
85
- * Adds an additional lookup, which is needed for certain situations like
86
- * multiple inline directives in the same string.
87
- *
88
- * @param {string} key - the lookup key
89
- * @param {string} statement - the raw statement with value to return
90
- */
91
- addLookup(key, statement){
92
- this.additionalLookups[key] = statement
93
- }
94
- /**
95
- * Builds the call to create a pool for child components.
96
- *
97
- * @param {string} poolDef - the name of the component class to pool, or if it
98
- * starts with @ then it is the path to a pool object (e.g. @..sharedPool ).
99
- * @param {string} key - the field on the props to pool by.
100
- */
101
- buildPoolInit (poolDef, key){
102
- let poolStatement
103
- // if (poolDef.startsWith('@')) {
104
- // poolStatement = this.expandDots(poolDef.substr(1))
105
- // } else {
106
- // console.log(key)
107
- if (key) {
108
- const keyFn = `function(props) {return props.${key}}`
109
- poolStatement = `component.pool(${poolDef}, ${keyFn})`
110
- } else {
111
- poolStatement = `component.pool(${poolDef})`
112
- }
113
- //}
114
- return poolStatement
115
- }
116
- /**
117
- * Expands a value slot.
118
- *
119
- */
120
- expandValueSlot(slot, inBuild=false) {
121
- if (slot && (slot !== '')) {
122
- // If it starts with () then we don't expand dots (treat as raw code).
123
- if (slot.startsWith('(')) {
124
- if (slot.endsWith(')')) {
125
- return slot.substr(1, slot.length - 2)
126
- } else {
127
- throw 'Value slot starting with "(" must also end with ")"'
128
- }
129
- }
130
- return this.expandDots(slot, inBuild)
131
- }
132
- }
133
- /**
134
- * Expands a value field's dots.
135
- * Works differently if it is a callback in Build.
136
- */
137
- expandDots(field, inBuild=false) {
138
- if (this.processAsStub) {
139
- if (inBuild) {
140
- if (field.startsWith('..')) {
141
- return `${componentRefInBuild}.parent.props.` + field.substr(2)
142
- } else if (field.startsWith('.')) {
143
- return `${componentRefInBuild}.parent.` + field.substr(1)
144
- }
145
- } else {
146
- if (field.startsWith('..')) {
147
- return `c.parent.props.` + field.substr(2)
148
- } else if (field.startsWith('.')) {
149
- return `c.parent.` + field.substr(1)
150
- }
151
- }
152
- } else {
153
- if (inBuild) {
154
- if (field.startsWith('..')) {
155
- return `${componentRefInBuild}.props.` + field.substr(2)
156
- } else if (field.startsWith('.')) {
157
- return `${componentRefInBuild}.` + field.substr(1)
158
- }
159
- } else {
160
- if (field.startsWith('..')) {
161
- return `p.` + field.substr(2)
162
- } else if (field.startsWith('.')) {
163
- return `c.` + field.substr(1)
164
- }
165
- }
166
- }
167
- return field
168
- }
169
- /**
170
- * Expands the props field.
171
- *
172
- * @param {string} field
173
- */
174
- expandProps(field) {
175
- return this.expandDots(field)
176
- }
177
- getUniqueKey() {
178
- this.seq ++
179
- return '___zzz___' + this.seq
180
- }
181
- }
182
-
183
- module.exports = {NodeData}
@@ -1,26 +0,0 @@
1
-
2
- /**
3
- * Constructor for watcher object.
4
- *
5
- * @param {string} watch - the field or wrapperMethod to watch.
6
- * @param {string} [converter] - the converter*
7
- * @param {string} [wrapperMethod] - the method on the wrapper*
8
- * @param {string} [extraArg] - And extra argument to pass to the wrapperMethod
9
- * @param {string} [lookup] - name of the lookup to use.
10
- *
11
- * All arguments passed in must have dots expanded already.
12
- *
13
- * - The converter will become a free function call if no wrapperMethod supplied.
14
- * - The wrapperMethod may use "@attName" syntax.
15
- * - Lookup and converter are mutually exclusive - only one must be supplied.
16
- *
17
- */
18
- function Watcher(watch, converter, wrapperMethod, extraArg, lookup) {
19
- this.watch = watch || ''
20
- this.converter = converter
21
- this.wrapperMethod = wrapperMethod
22
- this.extraArg = extraArg
23
- this.lookup = lookup
24
- }
25
-
26
- module.exports = {Watcher}