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.
- package/LICENSE.md +1 -1
- package/dist/ast-helpers.d.ts +10 -0
- package/dist/ast-helpers.js +52 -0
- package/dist/ast-helpers.js.map +1 -0
- package/dist/babel-types.d.ts +4 -0
- package/dist/babel-types.js +3 -0
- package/dist/babel-types.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +47 -0
- package/dist/config.js.map +1 -0
- package/dist/consolidation/ComponentDefinitionData.d.ts +29 -0
- package/dist/consolidation/ComponentDefinitionData.js +82 -0
- package/dist/consolidation/ComponentDefinitionData.js.map +1 -0
- package/dist/consolidation/consolidateComponent.d.ts +6 -0
- package/dist/consolidation/consolidateComponent.js +41 -0
- package/dist/consolidation/consolidateComponent.js.map +1 -0
- package/dist/consolidation/index.d.ts +2 -0
- package/dist/consolidation/index.js +8 -0
- package/dist/consolidation/index.js.map +1 -0
- package/dist/consolidation/processNodes.d.ts +3 -0
- package/dist/consolidation/processNodes.js +202 -0
- package/dist/consolidation/processNodes.js.map +1 -0
- package/dist/consolidation/types.d.ts +15 -0
- package/dist/consolidation/types.js +3 -0
- package/dist/consolidation/types.js.map +1 -0
- package/dist/consolidation/utils.d.ts +21 -0
- package/dist/consolidation/utils.js +91 -0
- package/dist/consolidation/utils.js.map +1 -0
- package/dist/consolidation/visibility.d.ts +5 -0
- package/dist/consolidation/visibility.js +43 -0
- package/dist/consolidation/visibility.js.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.js +40 -0
- package/dist/constants.js.map +1 -0
- package/dist/contexts/handlers.d.ts +18 -0
- package/dist/contexts/handlers.js +152 -0
- package/dist/contexts/handlers.js.map +1 -0
- package/dist/contexts/index.d.ts +2 -0
- package/dist/contexts/index.js +6 -0
- package/dist/contexts/index.js.map +1 -0
- package/dist/contexts/parameters.d.ts +8 -0
- package/dist/contexts/parameters.js +114 -0
- package/dist/contexts/parameters.js.map +1 -0
- package/dist/directives.d.ts +8 -0
- package/dist/directives.js +193 -0
- package/dist/directives.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.js +47 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +35 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/models/component.d.ts +25 -0
- package/dist/models/component.js +114 -0
- package/dist/models/component.js.map +1 -0
- package/dist/models/directive.d.ts +13 -0
- package/dist/models/directive.js +8 -0
- package/dist/models/directive.js.map +1 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.js +15 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/module.d.ts +12 -0
- package/dist/models/module.js +40 -0
- package/dist/models/module.js.map +1 -0
- package/dist/models/node.d.ts +107 -0
- package/dist/models/node.js +327 -0
- package/dist/models/node.js.map +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +66 -0
- package/dist/utils.js.map +1 -0
- package/dist/visitors/attribute.d.ts +10 -0
- package/dist/visitors/attribute.js +82 -0
- package/dist/visitors/attribute.js.map +1 -0
- package/dist/visitors/jsx.d.ts +13 -0
- package/dist/visitors/jsx.js +61 -0
- package/dist/visitors/jsx.js.map +1 -0
- package/dist/visitors/program.d.ts +12 -0
- package/dist/visitors/program.js +26 -0
- package/dist/visitors/program.js.map +1 -0
- package/dist/writers/define-component.d.ts +7 -0
- package/dist/writers/define-component.js +101 -0
- package/dist/writers/define-component.js.map +1 -0
- package/dist/writers/index.d.ts +1 -0
- package/dist/writers/index.js +7 -0
- package/dist/writers/index.js.map +1 -0
- package/package.json +20 -10
- package/README.md +0 -3
- package/lib/_config/directives.js +0 -356
- package/lib/_config/index.js +0 -2
- package/lib/_config/loader.js +0 -43
- package/lib/_config/parse_directives.js +0 -63
- package/lib/config.js +0 -263
- package/lib/convert.js +0 -27
- package/lib/definitions/constants.js +0 -73
- package/lib/definitions/node_data.js +0 -183
- package/lib/definitions/watcher.js +0 -26
- package/lib/generate/code_generator.js +0 -333
- package/lib/generate/statement_builders.js +0 -130
- package/lib/help-system/browser-code.js +0 -50
- package/lib/help-system/entry.js +0 -92
- package/lib/help-system/error-display.js +0 -20
- package/lib/help-system/styles.css +0 -25
- package/lib/import-checker.js +0 -35
- package/lib/index.js +0 -47
- package/lib/jsx/component_dom.js +0 -40
- package/lib/jsx/contexts.js +0 -121
- package/lib/jsx/extract.js +0 -214
- package/lib/jsx/parse.js +0 -98
- package/lib/parse/component_templates.js +0 -44
- package/lib/parse/inline_directives.js +0 -318
- package/lib/parse/parse_node.js +0 -73
- package/lib/polyfills.js +0 -10
- package/lib/utils/babel.js +0 -100
- package/lib/utils/dom.js +0 -174
- package/lib/utils/misc.js +0 -152
- package/lib_old/handlers.js +0 -52
- package/lib_old/index.js +0 -145
package/lib/utils/misc.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Funtionality for working with JavaScript
|
|
3
|
-
*/
|
|
4
|
-
const isFunc = (def) => typeof def === 'function'
|
|
5
|
-
|
|
6
|
-
const isUnd = (def) => def === undefined
|
|
7
|
-
|
|
8
|
-
const splitTrim = (str, char) => str.split(char).map(item => item.trim())
|
|
9
|
-
|
|
10
|
-
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1)
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
* Converts an array of objects to one object with arrays.
|
|
14
|
-
*
|
|
15
|
-
* in: [{k: 'a', ...}, {k: 'b', ...}]
|
|
16
|
-
* out: {a: [...], b: [...]}
|
|
17
|
-
*/
|
|
18
|
-
const groupArray = (ar, key, f) => {
|
|
19
|
-
const obj = {}
|
|
20
|
-
ar.forEach(i => {
|
|
21
|
-
let k = i[key]
|
|
22
|
-
if (!obj.hasOwnProperty(k)) {
|
|
23
|
-
obj[k] = []
|
|
24
|
-
}
|
|
25
|
-
obj[k].push(f(i))
|
|
26
|
-
})
|
|
27
|
-
return obj
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns undefined if string is only whitespace, else the original string.
|
|
32
|
-
*/
|
|
33
|
-
function clearIfEmpty(str) {
|
|
34
|
-
if (str.trim().length > 0) {
|
|
35
|
-
return str
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const arrayStartsWith = (origin, test) => {
|
|
40
|
-
if (test.length <= origin.length) {
|
|
41
|
-
return false
|
|
42
|
-
}
|
|
43
|
-
for (const [i, v] of origin.entries()) {
|
|
44
|
-
if (test[i] !== v) {
|
|
45
|
-
return false
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Replaces arg variables if found.
|
|
53
|
-
*
|
|
54
|
-
* replaceArgs("foo(n, c, o)", "c", "component") >> "foo(n, component, o)"
|
|
55
|
-
* replaceArgs("foo(n, c, o)", "X", "X") >> "foo(n, c, o)"
|
|
56
|
-
*
|
|
57
|
-
* Only works on last set of brackets, so:
|
|
58
|
-
*
|
|
59
|
-
* replaceArgs("foo(n, c, o).bar(c, p)", "c", "X") >> "foo(n, c, o).bar(X, p)"
|
|
60
|
-
*
|
|
61
|
-
* @param {string} str
|
|
62
|
-
* @param {string} oldArg
|
|
63
|
-
* @param {string} newArg
|
|
64
|
-
*/
|
|
65
|
-
const replaceArgs = (str, oldArg, newArg) => {
|
|
66
|
-
const openArgBracket = str.lastIndexOf("(");
|
|
67
|
-
const closeArgBracket = str.lastIndexOf(")");
|
|
68
|
-
if (openArgBracket >=0 && closeArgBracket >= openArgBracket) {
|
|
69
|
-
const argString = str.slice(openArgBracket + 1, closeArgBracket)
|
|
70
|
-
const argsArray = argString.split(',').map(s => s.trim())
|
|
71
|
-
const argPostition = argsArray.indexOf(oldArg)
|
|
72
|
-
if (argPostition >= 0) {
|
|
73
|
-
argsArray[argPostition] = newArg
|
|
74
|
-
return str.slice(0, openArgBracket + 1) + argsArray.join(',') + ')'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return str
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/*
|
|
81
|
-
* Given an array of nodeIndexPaths such as
|
|
82
|
-
*
|
|
83
|
-
* [
|
|
84
|
-
* [0],
|
|
85
|
-
* [0, 1],
|
|
86
|
-
* [0, 2],
|
|
87
|
-
* [1],
|
|
88
|
-
* ]
|
|
89
|
-
*
|
|
90
|
-
* It returns an array the number of nested items, like so:
|
|
91
|
-
*
|
|
92
|
-
* [2, 0, 0, 0]
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
const extractShieldCounts = (paths) => {
|
|
97
|
-
const processedPaths = []
|
|
98
|
-
|
|
99
|
-
paths.forEach(path => {
|
|
100
|
-
processedPaths.forEach(processed => {
|
|
101
|
-
if (arrayStartsWith(processed.path, path)) {
|
|
102
|
-
processed.count ++
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
processedPaths.push({path: path, count: 0})
|
|
106
|
-
})
|
|
107
|
-
return processedPaths.map(i => i.count)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const escapeSingleQuotes = (text) => text.replace(/'/g, "\\'")
|
|
112
|
-
const escapeDoubleQuotes = (text) => text.replace(/"/g, '\\"')
|
|
113
|
-
|
|
114
|
-
const trimChar = (string, charToRemove) => {
|
|
115
|
-
while(string.charAt(0)==charToRemove) {
|
|
116
|
-
string = string.substring(1);
|
|
117
|
-
}
|
|
118
|
-
while(string.charAt(string.length-1)==charToRemove) {
|
|
119
|
-
string = string.substring(0,string.length-1);
|
|
120
|
-
}
|
|
121
|
-
return string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const trimChars = (str, chars) => {
|
|
125
|
-
var start = 0,
|
|
126
|
-
end = str.length;
|
|
127
|
-
|
|
128
|
-
while(start < end && chars.indexOf(str[start]) >= 0)
|
|
129
|
-
++start;
|
|
130
|
-
|
|
131
|
-
while(end > start && chars.indexOf(str[end - 1]) >= 0)
|
|
132
|
-
--end;
|
|
133
|
-
|
|
134
|
-
return (start > 0 || end < str.length) ? str.substring(start, end) : str;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
module.exports = {
|
|
139
|
-
arrayStartsWith,
|
|
140
|
-
capitalize,
|
|
141
|
-
clearIfEmpty,
|
|
142
|
-
escapeSingleQuotes,
|
|
143
|
-
escapeDoubleQuotes,
|
|
144
|
-
extractShieldCounts,
|
|
145
|
-
groupArray,
|
|
146
|
-
isFunc,
|
|
147
|
-
isUnd,
|
|
148
|
-
replaceArgs,
|
|
149
|
-
splitTrim,
|
|
150
|
-
trimChar,
|
|
151
|
-
trimChars
|
|
152
|
-
}
|
package/lib_old/handlers.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const {RequestsHelp, FrameworkError} = require('./definitions/constants')
|
|
2
|
-
const {CodeGenerator} = require('./generate/code_generator')
|
|
3
|
-
const {buildHelpLoaderStatements} = require('./help-system/entry')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handles an
|
|
7
|
-
* @param {string} componentName - the name of the component definition
|
|
8
|
-
* @param {string} html - The html string.
|
|
9
|
-
* @param {*} path - the babel AST path
|
|
10
|
-
*/
|
|
11
|
-
const handleHtml = (componentName, html, path) => {
|
|
12
|
-
return generateStatements(componentName, html, false, path)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const handleStubs = (componentName, stubs, path) => {
|
|
17
|
-
const statements = []
|
|
18
|
-
for (const [stubName, stubHtml] of Object.entries(stubs)) {
|
|
19
|
-
let anonymousCls = path.scope.generateUidIdentifier("sv").name
|
|
20
|
-
statements.push(`var ${anonymousCls} = ${componentName}.prototype.__sv();`)
|
|
21
|
-
statements.push(`${componentName}.prototype.__stubs__${stubName} = ${anonymousCls};`)
|
|
22
|
-
generateStatements(anonymousCls, stubHtml, true, path).forEach(statement => {
|
|
23
|
-
statements.push(statement)
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
return statements
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const generateStatements = (className, html, processAsStub, path) => {
|
|
31
|
-
let statements
|
|
32
|
-
try {
|
|
33
|
-
const builder = new CodeGenerator(className, html, processAsStub, path)
|
|
34
|
-
statements = builder.buildStatements()
|
|
35
|
-
} catch (error) {
|
|
36
|
-
if (error instanceof RequestsHelp) {
|
|
37
|
-
return buildHelpLoaderStatements(error.topic)
|
|
38
|
-
} else if (error instanceof FrameworkError) {
|
|
39
|
-
const bar = '|'
|
|
40
|
-
const hr = '|----------------------------------------------------------------------'
|
|
41
|
-
const header = '| Error in component definition (specific location not available yet).'
|
|
42
|
-
const errorMessage = `${bar} > ${error.msg}`
|
|
43
|
-
const fullMessage = ['\n', hr, bar, header, bar, errorMessage, bar, hr].join('\n')
|
|
44
|
-
throw path.buildCodeFrameError(fullMessage)
|
|
45
|
-
} else {
|
|
46
|
-
throw error
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return statements
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
module.exports = {handleHtml, handleStubs}
|
package/lib_old/index.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
const t = require('@babel/types')
|
|
2
|
-
const {handleHtml, handleStubs} = require('./handlers')
|
|
3
|
-
const {
|
|
4
|
-
getNodeHtmlString,
|
|
5
|
-
getNodeHtmlObjectOfStrings,
|
|
6
|
-
insertStatementsAfter,
|
|
7
|
-
removeWallaceDefs
|
|
8
|
-
} = require('./utils/babel')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = () => {
|
|
12
|
-
return {
|
|
13
|
-
visitor: {
|
|
14
|
-
MemberExpression(path) {
|
|
15
|
-
/* This just replaces this:
|
|
16
|
-
|
|
17
|
-
const Button = Foo.__ex__(
|
|
18
|
-
|
|
19
|
-
with:
|
|
20
|
-
|
|
21
|
-
const Button = Foo.prototype.__ex(
|
|
22
|
-
|
|
23
|
-
But it also seems to be handled further down?
|
|
24
|
-
Can this be merged into CallExpression?
|
|
25
|
-
*/
|
|
26
|
-
if (path.node.property.name === '__ex__') {
|
|
27
|
-
const baseClass = path.node.object.name
|
|
28
|
-
path.replaceWithSourceString(`${baseClass}.prototype.__ex`)
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
CallExpression(path) {
|
|
32
|
-
const callee = path.node.callee
|
|
33
|
-
if (
|
|
34
|
-
callee &&
|
|
35
|
-
callee.type === 'MemberExpression' &&
|
|
36
|
-
callee.property.name === '__ex__' &&
|
|
37
|
-
path.parent &&
|
|
38
|
-
path.parent.type === 'VariableDeclarator'
|
|
39
|
-
) {
|
|
40
|
-
|
|
41
|
-
const baseClass = callee.object.name
|
|
42
|
-
const componentName = path.parent.id.name
|
|
43
|
-
const nodeToInsertAfter = path.parentPath.parentPath
|
|
44
|
-
const data = parseExArguments(path)
|
|
45
|
-
|
|
46
|
-
// data seems to have [stubs, html, constructor, prototype] - but do we want
|
|
47
|
-
// to allows all of those?
|
|
48
|
-
|
|
49
|
-
if (data.html) {
|
|
50
|
-
let statements = handleHtml(componentName, getNodeHtmlString(data.html), path)
|
|
51
|
-
insertStatementsAfter(nodeToInsertAfter, statements)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (data.stubs) {
|
|
55
|
-
let statements = handleStubs(componentName, getNodeHtmlObjectOfStrings(data.stubs), path)
|
|
56
|
-
insertStatementsAfter(nodeToInsertAfter, statements)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const newArgs = [t.identifier(baseClass)]
|
|
60
|
-
|
|
61
|
-
// If either is supplied, we must still include both arguments to the call.
|
|
62
|
-
let protoArg, constructorArg
|
|
63
|
-
if (data.hasOwnProperty('prototype')) {
|
|
64
|
-
protoArg = data.prototype
|
|
65
|
-
}
|
|
66
|
-
if (data.hasOwnProperty('constructor')) {
|
|
67
|
-
constructorArg = data.constructor
|
|
68
|
-
}
|
|
69
|
-
if (protoArg || constructorArg) {
|
|
70
|
-
newArgs.push(protoArg || t.identifier('undefined'))
|
|
71
|
-
newArgs.push(constructorArg)
|
|
72
|
-
}
|
|
73
|
-
path.node.arguments = newArgs
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
Class(path, state) {
|
|
77
|
-
if (path.type === 'ClassDeclaration') {
|
|
78
|
-
|
|
79
|
-
// TODO: tidy up how args are passed, and whether we bother with componentData...
|
|
80
|
-
let html, stubs, componentName = path.node.id.name
|
|
81
|
-
|
|
82
|
-
// Iterate over class nodes to find ones we care about
|
|
83
|
-
for (let node of path.node.body.body) {
|
|
84
|
-
let propName = node.key.name
|
|
85
|
-
if (propName === '__html__' || propName === '__clone__') {
|
|
86
|
-
html = getNodeHtmlString(node.value)
|
|
87
|
-
} else if (propName === '__stubs__') {
|
|
88
|
-
stubs = getNodeHtmlObjectOfStrings(node.value)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
removeWallaceDefs(path)
|
|
92
|
-
if (stubs) {
|
|
93
|
-
insertStatementsAfter(path, handleStubs(componentName, stubs, path))
|
|
94
|
-
}
|
|
95
|
-
if (html) {
|
|
96
|
-
insertStatementsAfter(path, handleHtml(componentName, html, path))
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const allowedHtmlTypes = [
|
|
106
|
-
'TaggedTemplateExpression',
|
|
107
|
-
'TemplateLiteral',
|
|
108
|
-
'StringLiteral',
|
|
109
|
-
'JSXElement'
|
|
110
|
-
]
|
|
111
|
-
const eitherAllowedTypes = [...allowedHtmlTypes, 'ObjectExpression']
|
|
112
|
-
|
|
113
|
-
const assertType = (path, thing, types, description) => {
|
|
114
|
-
if (!types.includes(thing.type)) {
|
|
115
|
-
throw path.buildCodeFrameError(`${description} must be of type ${types} but is a ${thing.type}.`)
|
|
116
|
-
}
|
|
117
|
-
return thing
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const parseExArguments = (path) => {
|
|
121
|
-
const args = path.node.arguments
|
|
122
|
-
const data = {}
|
|
123
|
-
|
|
124
|
-
if (args.length == 1) {
|
|
125
|
-
// Must be html or an ObjectExpression - not an identifier
|
|
126
|
-
const argument = assertType(path, args[0], eitherAllowedTypes, 'Argument to __ex__()')
|
|
127
|
-
if (argument.type == 'ObjectExpression') {
|
|
128
|
-
argument.properties.forEach(element => {
|
|
129
|
-
|
|
130
|
-
// Does this get "stubs"?
|
|
131
|
-
data[element.key.name] = element.value
|
|
132
|
-
})
|
|
133
|
-
} else {
|
|
134
|
-
data['html'] = assertType(path, args[0], allowedHtmlTypes, 'Argument to __ex__()')
|
|
135
|
-
}
|
|
136
|
-
} else if (args.length == 2) {
|
|
137
|
-
// Must be __ex__(html, methods) where methods can be an object literal or an identifier.
|
|
138
|
-
|
|
139
|
-
data['html'] = assertType(path, args[0], allowedHtmlTypes, 'First Argument to __ex__()')
|
|
140
|
-
data['prototype'] = assertType(path, args[1], ['ObjectExpression', 'Identifier'], 'Second Argument to __ex__()')
|
|
141
|
-
} else {
|
|
142
|
-
throw path.buildCodeFrameError(`__ex__() takes either one or two arguments, Received ${args.length}.`)
|
|
143
|
-
}
|
|
144
|
-
return data
|
|
145
|
-
}
|