boxwood 0.60.2 → 0.61.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.
- package/README.md +0 -358
- package/index.js +402 -4
- package/package.json +12 -37
- package/src/Bundler.js +0 -13
- package/src/Cache.js +0 -35
- package/src/Compiler.js +0 -28
- package/src/Importer.js +0 -142
- package/src/Optimizer.js +0 -96
- package/src/Scope.js +0 -20
- package/src/Statistics.js +0 -58
- package/src/bundlers/esbuild/index.js +0 -55
- package/src/bundlers/esbuild/plugins/css.js +0 -40
- package/src/bundlers/esbuild/plugins/html.js +0 -27
- package/src/bundlers/esbuild/plugins/image.js +0 -38
- package/src/bundlers/esbuild/plugins/resolve.js +0 -11
- package/src/bundlers/esbuild/plugins/yaml.js +0 -38
- package/src/bundlers/esbuild/utilities/asset.js +0 -19
- package/src/bundlers/rollup.js +0 -38
- package/src/compile.js +0 -6
- package/src/compilers/any/Compiler.js +0 -16
- package/src/compilers/compile.js +0 -17
- package/src/compilers/html/Analyzer.js +0 -24
- package/src/compilers/html/Compiler.js +0 -47
- package/src/compilers/html/Generator.js +0 -19
- package/src/compilers/html/Parser.js +0 -11
- package/src/compilers/html/Preprocessor.js +0 -130
- package/src/compilers/html/Renderer.js +0 -167
- package/src/compilers/html/Transpiler.js +0 -76
- package/src/compilers/js/Bundler.js +0 -84
- package/src/compilers/js/Compiler/index.js +0 -27
- package/src/conditions/isEqual.js +0 -5
- package/src/lexers/html.js +0 -49
- package/src/lexers/internal.js +0 -49
- package/src/linters/html/bracket.js +0 -36
- package/src/linters/html/component.js +0 -43
- package/src/linters/html/import.js +0 -35
- package/src/linters/html/index.js +0 -19
- package/src/linters/html/tag.js +0 -36
- package/src/optimizers/html.js +0 -15
- package/src/plugins/BoxModelPlugin/index.js +0 -109
- package/src/plugins/CurlyStylesPlugin/index.js +0 -39
- package/src/plugins/DataPlugin/index.js +0 -53
- package/src/plugins/InlinePlugin/css.js +0 -131
- package/src/plugins/InlinePlugin/index.js +0 -39
- package/src/plugins/InternationalizationPlugin/index.js +0 -111
- package/src/plugins/Plugin.js +0 -22
- package/src/plugins/ScopedStylesPlugin/css.js +0 -56
- package/src/plugins/ScopedStylesPlugin/html.js +0 -112
- package/src/plugins/ScopedStylesPlugin/index.js +0 -48
- package/src/plugins/SwappedStylesPlugin/index.js +0 -20
- package/src/render.js +0 -48
- package/src/tags/case.js +0 -28
- package/src/tags/catch.js +0 -17
- package/src/tags/data.js +0 -7
- package/src/tags/default.js +0 -20
- package/src/tags/doctype.js +0 -8
- package/src/tags/else.js +0 -18
- package/src/tags/elseif.js +0 -25
- package/src/tags/elseunless.js +0 -30
- package/src/tags/font.js +0 -37
- package/src/tags/for.js +0 -90
- package/src/tags/foreach.js +0 -80
- package/src/tags/if.js +0 -19
- package/src/tags/img.js +0 -25
- package/src/tags/index.js +0 -53
- package/src/tags/link.js +0 -14
- package/src/tags/script/index.js +0 -83
- package/src/tags/script/scoped.js +0 -26
- package/src/tags/slot.js +0 -9
- package/src/tags/style.js +0 -9
- package/src/tags/switch.js +0 -13
- package/src/tags/template.js +0 -22
- package/src/tags/translate.js +0 -22
- package/src/tags/translation.js +0 -38
- package/src/tags/try.js +0 -17
- package/src/tags/unless.js +0 -24
- package/src/tags/var.js +0 -32
- package/src/transpilers/css/index.js +0 -34
- package/src/transpilers/html/expression.js +0 -101
- package/src/transpilers/html/index.js +0 -189
- package/src/transpilers/html/node.js +0 -46
- package/src/transpilers/html/tags/any.js +0 -53
- package/src/transpilers/html/tags/comment.js +0 -7
- package/src/transpilers/html/tags/doctype.js +0 -6
- package/src/transpilers/html/tags/for.js +0 -30
- package/src/transpilers/html/tags/if.js +0 -55
- package/src/transpilers/html/tags/import.js +0 -7
- package/src/transpilers/html/tags/index.js +0 -13
- package/src/transpilers/html/tags/partial.js +0 -17
- package/src/transpilers/html/tags/slot.js +0 -7
- package/src/transpilers/html/tags/text.js +0 -6
- package/src/transpilers/html/tags/try.js +0 -30
- package/src/transpilers/html/tags/unless.js +0 -58
- package/src/transpilers/html/utilities/path.js +0 -9
- package/src/utilities/action.js +0 -208
- package/src/utilities/array.js +0 -80
- package/src/utilities/assets.js +0 -18
- package/src/utilities/ast.js +0 -13
- package/src/utilities/attributes.js +0 -23
- package/src/utilities/collect.js +0 -404
- package/src/utilities/conditions.js +0 -159
- package/src/utilities/convert.js +0 -359
- package/src/utilities/data.js +0 -55
- package/src/utilities/enum.js +0 -103
- package/src/utilities/errors.js +0 -96
- package/src/utilities/factory.js +0 -237
- package/src/utilities/files.js +0 -55
- package/src/utilities/filters.js +0 -140
- package/src/utilities/globals.js +0 -43
- package/src/utilities/html.js +0 -60
- package/src/utilities/inline.js +0 -200
- package/src/utilities/js.js +0 -15
- package/src/utilities/keywords.js +0 -35
- package/src/utilities/log.js +0 -31
- package/src/utilities/node.js +0 -149
- package/src/utilities/object.js +0 -8
- package/src/utilities/optimize.js +0 -268
- package/src/utilities/options.js +0 -99
- package/src/utilities/request.js +0 -13
- package/src/utilities/string.js +0 -144
- package/src/utilities/style.js +0 -15
- package/src/utilities/translations.js +0 -78
- package/src/utilities/url.js +0 -24
- package/src/vdom/browser/app.js +0 -19
- package/src/vdom/browser/diff.js +0 -104
- package/src/vdom/browser/index.js +0 -15
- package/src/vdom/browser/mount.js +0 -10
- package/src/vdom/browser/render.js +0 -66
- package/src/vdom/browser/replace.js +0 -7
- package/src/vdom/node.js +0 -10
- package/src/vdom/nodes.js +0 -116
- package/src/vdom/server/State.js +0 -21
- package/src/vdom/server/boxwood.js +0 -5
- package/src/vdom/server/index.js +0 -19
- package/src/vdom/server/render.js +0 -66
- package/src/vdom/tag.js +0 -33
- package/src/vdom/utilities/classes.js +0 -22
- package/src/vdom/utilities/css.js +0 -17
- package/src/vdom/utilities/escape.js +0 -50
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
4
|
-
const { deduceParams } = require('./expression')
|
|
5
|
-
const BoxModelPlugin = require('../../plugins/BoxModelPlugin')
|
|
6
|
-
const CurlyStylesPlugin = require('../../plugins/CurlyStylesPlugin')
|
|
7
|
-
const { parse, walk } = require('../../utilities/html')
|
|
8
|
-
const { findAttributeByKey } = require('../../utilities/attributes')
|
|
9
|
-
const { transpileNode } = require('./node')
|
|
10
|
-
// TODO: initial transpilation, move to a separate dir? or inline here after removing the outdated compiler
|
|
11
|
-
const Transpiler = require('../../compilers/html/Transpiler')
|
|
12
|
-
const { pathToIdentifier } = require('./utilities/path')
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
ArrayExpression,
|
|
16
|
-
Identifier,
|
|
17
|
-
ImportDeclaration,
|
|
18
|
-
ImportDefaultSpecifier,
|
|
19
|
-
ImportSpecifier,
|
|
20
|
-
Literal
|
|
21
|
-
} = AbstractSyntaxTree
|
|
22
|
-
|
|
23
|
-
const program = (body) => {
|
|
24
|
-
const params = deduceParams(body)
|
|
25
|
-
return AbstractSyntaxTree.program(
|
|
26
|
-
AbstractSyntaxTree.template(`
|
|
27
|
-
export default function (%= params %) {
|
|
28
|
-
return <%= body %>
|
|
29
|
-
}
|
|
30
|
-
`, { params, body })
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function createComponentImportDeclarations (imports) {
|
|
35
|
-
return imports.map(node => {
|
|
36
|
-
const { path } = node
|
|
37
|
-
return new ImportDeclaration({
|
|
38
|
-
specifiers: [
|
|
39
|
-
new ImportDefaultSpecifier({
|
|
40
|
-
local: new Identifier(pathToIdentifier(path))
|
|
41
|
-
})
|
|
42
|
-
],
|
|
43
|
-
source: new Literal(path)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function deducePartials (tree) {
|
|
49
|
-
return tree.find('Identifier[partial=true]')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function createPartialImportDeclarations (imports) {
|
|
53
|
-
return imports.map(node => {
|
|
54
|
-
const { name, path } = node
|
|
55
|
-
return new ImportDeclaration({
|
|
56
|
-
specifiers: [
|
|
57
|
-
new ImportDefaultSpecifier({
|
|
58
|
-
local: new Identifier(name)
|
|
59
|
-
})
|
|
60
|
-
],
|
|
61
|
-
source: new Literal(path)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function deduceComponents (htmlTree) {
|
|
67
|
-
const nodes = []
|
|
68
|
-
walk(htmlTree, node => {
|
|
69
|
-
if (node.tagName === 'import') {
|
|
70
|
-
nodes.push({
|
|
71
|
-
tag: node.attributes[0].key,
|
|
72
|
-
path: findAttributeByKey(node.attributes, 'from').value
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
return nodes
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function deduceBoxwoodImports (tree) {
|
|
80
|
-
const methods = ['tag', 'escape']
|
|
81
|
-
const imports = []
|
|
82
|
-
methods.forEach(method => {
|
|
83
|
-
if (tree.has(`CallExpression[callee.name="${method}"]`)) {
|
|
84
|
-
imports.push(method)
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
return imports
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function createBoxwoodImportDeclaration (imports) {
|
|
91
|
-
return new ImportDeclaration({
|
|
92
|
-
specifiers: imports.map(name => (new ImportSpecifier({
|
|
93
|
-
local: new Identifier(name),
|
|
94
|
-
imported: new Identifier(name)
|
|
95
|
-
}))),
|
|
96
|
-
source: new Literal('boxwood')
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function prerunPlugins (tree, plugins) {
|
|
101
|
-
plugins.forEach(plugin => plugin.beforeprerun())
|
|
102
|
-
walk(tree, node => {
|
|
103
|
-
plugins.forEach(plugin => {
|
|
104
|
-
plugin.prerun({
|
|
105
|
-
tag: node.tagName,
|
|
106
|
-
keys: node.attributes ? node.attributes.map(attribute => attribute.key) : [],
|
|
107
|
-
attrs: node.attributes || [],
|
|
108
|
-
fragment: node
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
})
|
|
112
|
-
plugins.forEach(plugin => plugin.afterprerun())
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function body (tree, options) {
|
|
116
|
-
const plugins = [
|
|
117
|
-
// new DataPlugin(),
|
|
118
|
-
// new InlinePlugin(),
|
|
119
|
-
new BoxModelPlugin(options),
|
|
120
|
-
new CurlyStylesPlugin()
|
|
121
|
-
// new ScopedStylesPlugin(),
|
|
122
|
-
// new SwappedStylesPlugin(),
|
|
123
|
-
// new InternationalizationPlugin({ translations, filters, errors })
|
|
124
|
-
]
|
|
125
|
-
prerunPlugins(tree, plugins)
|
|
126
|
-
return tree.length === 1
|
|
127
|
-
? transpileNode({ node: tree[0], parent: tree, index: 0 })
|
|
128
|
-
: new ArrayExpression(
|
|
129
|
-
tree
|
|
130
|
-
.map((node, index) => transpileNode({ node, parent: tree, index }))
|
|
131
|
-
.filter(Boolean)
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function transpile (source, options) {
|
|
136
|
-
source = new Transpiler().transpile(source)
|
|
137
|
-
|
|
138
|
-
const tree = parse(source)
|
|
139
|
-
const outputTree = new AbstractSyntaxTree(
|
|
140
|
-
program(body(tree, options))
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
let imports
|
|
144
|
-
|
|
145
|
-
imports = deduceComponents(tree)
|
|
146
|
-
if (imports.length > 0) {
|
|
147
|
-
outputTree.prepend(createComponentImportDeclarations(imports))
|
|
148
|
-
|
|
149
|
-
outputTree.replace(node => {
|
|
150
|
-
if (node.type === 'CallExpression' && node.callee.name === 'tag') {
|
|
151
|
-
imports.forEach(leaf => {
|
|
152
|
-
if (node.arguments[0].value === leaf.tag) {
|
|
153
|
-
node.callee.name = pathToIdentifier(leaf.path)
|
|
154
|
-
node.arguments.shift()
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// console.log(outputTree.source)
|
|
162
|
-
|
|
163
|
-
imports = deducePartials(outputTree)
|
|
164
|
-
if (imports.length > 0) {
|
|
165
|
-
outputTree.prepend(createPartialImportDeclarations(imports))
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
imports = deduceBoxwoodImports(outputTree)
|
|
169
|
-
if (imports.length > 0) {
|
|
170
|
-
outputTree.prepend(createBoxwoodImportDeclaration(imports))
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const block = outputTree.first('ExportDefaultDeclaration > FunctionDeclaration > BlockStatement')
|
|
174
|
-
const statement = block.body.find(node => node.type === 'ReturnStatement')
|
|
175
|
-
if (statement.argument.type === 'ArrayExpression') {
|
|
176
|
-
statement.argument.elements = statement.argument.elements.filter(element => {
|
|
177
|
-
if (element.type === 'Literal' && element.value === null) {
|
|
178
|
-
return false
|
|
179
|
-
}
|
|
180
|
-
return true
|
|
181
|
-
})
|
|
182
|
-
if (statement.argument.elements.length === 1) {
|
|
183
|
-
statement.argument = statement.argument.elements[0]
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return outputTree.source
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
module.exports = { transpile }
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
4
|
-
const tags = require('./tags')
|
|
5
|
-
|
|
6
|
-
function transpileNode ({ node: htmlNode, parent, index }) {
|
|
7
|
-
const { type, tagName } = htmlNode
|
|
8
|
-
if (type === 'text') {
|
|
9
|
-
return tags.text(htmlNode)
|
|
10
|
-
} else if (type === 'comment') {
|
|
11
|
-
return tags.comment()
|
|
12
|
-
} else if (tagName === 'if') {
|
|
13
|
-
const statement = tags.if(htmlNode, parent, index, transpileNode)
|
|
14
|
-
const { expression } = AbstractSyntaxTree.iife(statement)
|
|
15
|
-
return expression
|
|
16
|
-
} else if (tagName === 'else') {
|
|
17
|
-
return null
|
|
18
|
-
} else if (tagName === 'elseif') {
|
|
19
|
-
return null
|
|
20
|
-
} else if (tagName === 'unless') {
|
|
21
|
-
const statement = tags.unless(htmlNode, parent, index, transpileNode)
|
|
22
|
-
const { expression } = AbstractSyntaxTree.iife(statement)
|
|
23
|
-
return expression
|
|
24
|
-
} else if (tagName === 'elseunless') {
|
|
25
|
-
return null
|
|
26
|
-
} else if (tagName === 'try') {
|
|
27
|
-
const statement = tags.try(htmlNode, parent, index, transpileNode)
|
|
28
|
-
const { expression } = AbstractSyntaxTree.iife(statement)
|
|
29
|
-
return expression
|
|
30
|
-
} else if (tagName === 'catch') {
|
|
31
|
-
return null
|
|
32
|
-
} else if (tagName === 'for') {
|
|
33
|
-
return tags.for(htmlNode, parent, index, transpileNode)
|
|
34
|
-
} else if (tagName === 'import') {
|
|
35
|
-
return tags.import(htmlNode)
|
|
36
|
-
} else if (tagName === '!doctype') {
|
|
37
|
-
return tags.doctype()
|
|
38
|
-
} else if (tagName === 'partial') {
|
|
39
|
-
return tags.partial(htmlNode)
|
|
40
|
-
} else if (tagName === 'slot') {
|
|
41
|
-
return tags.slot(htmlNode)
|
|
42
|
-
}
|
|
43
|
-
return tags.any(htmlNode, transpileNode)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = { transpileNode }
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
const { transpileExpression } = require('../expression')
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
ArrayExpression,
|
|
6
|
-
CallExpression,
|
|
7
|
-
Identifier,
|
|
8
|
-
Literal,
|
|
9
|
-
ObjectExpression,
|
|
10
|
-
Property
|
|
11
|
-
} = AbstractSyntaxTree
|
|
12
|
-
|
|
13
|
-
function mapAttributes (attributes) {
|
|
14
|
-
function getAttributeValue (value) {
|
|
15
|
-
if (value === null) { return new Literal(true) }
|
|
16
|
-
return transpileExpression(value, false)
|
|
17
|
-
}
|
|
18
|
-
return attributes.length > 0
|
|
19
|
-
? new ObjectExpression({
|
|
20
|
-
properties: attributes.map(attribute => {
|
|
21
|
-
return new Property({
|
|
22
|
-
key: new Identifier(attribute.key),
|
|
23
|
-
value: getAttributeValue(attribute.value),
|
|
24
|
-
kind: 'init',
|
|
25
|
-
computed: false,
|
|
26
|
-
method: false,
|
|
27
|
-
shorthand: false
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
: new ObjectExpression({ properties: [] })
|
|
32
|
-
}
|
|
33
|
-
function mapChildren (children, transpileNode) {
|
|
34
|
-
return children.length > 0 && new ArrayExpression({
|
|
35
|
-
elements: children.map((childNode, index) => {
|
|
36
|
-
return transpileNode({ node: childNode, parent: children, index })
|
|
37
|
-
}).filter(Boolean)
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function any (htmlNode, transpileNode) {
|
|
42
|
-
const { tagName, attributes, children } = htmlNode
|
|
43
|
-
return new CallExpression({
|
|
44
|
-
callee: new Identifier('tag'),
|
|
45
|
-
arguments: [
|
|
46
|
-
new Literal(tagName),
|
|
47
|
-
mapAttributes(attributes),
|
|
48
|
-
mapChildren(children, transpileNode)
|
|
49
|
-
].filter(Boolean)
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = any
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
const { Identifier } = AbstractSyntaxTree
|
|
3
|
-
|
|
4
|
-
let FOR_LOOP_INDEX = 0
|
|
5
|
-
|
|
6
|
-
function mapForStatement (htmlNode, parent, index, transpileNode) {
|
|
7
|
-
FOR_LOOP_INDEX++
|
|
8
|
-
const [node] = AbstractSyntaxTree.template(`
|
|
9
|
-
(function () {
|
|
10
|
-
var __output__ = [];
|
|
11
|
-
for (var <%= index %> = 0, <%= length %> = <%= array %>.length; <%= index %> < <%= length %>; <%= index %>++) {
|
|
12
|
-
var <%= item %> = <%= array %>[<%= index %>];
|
|
13
|
-
__output__.push(%= children %);
|
|
14
|
-
}
|
|
15
|
-
return __output__;
|
|
16
|
-
})();
|
|
17
|
-
`, {
|
|
18
|
-
index: new Identifier(`__i${FOR_LOOP_INDEX}__`),
|
|
19
|
-
length: new Identifier(`__ilen${FOR_LOOP_INDEX}__`),
|
|
20
|
-
item: new Identifier(htmlNode.attributes[0].key),
|
|
21
|
-
// TODO we should not mark params which were created on the fly, e.g. for nested loops
|
|
22
|
-
array: new Identifier({ name: htmlNode.attributes[2].key, parameter: true }),
|
|
23
|
-
children: htmlNode.children.map((child, index) =>
|
|
24
|
-
transpileNode({ node: child, parent: htmlNode, index: index })
|
|
25
|
-
)
|
|
26
|
-
})
|
|
27
|
-
return node.expression
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = mapForStatement
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
const { transpileExpression } = require('../expression')
|
|
3
|
-
const { isCurlyTag } = require('../../../utilities/string')
|
|
4
|
-
|
|
5
|
-
const { BlockStatement, Literal, Identifier, IfStatement, ReturnStatement } = AbstractSyntaxTree
|
|
6
|
-
|
|
7
|
-
function mapIfStatement (htmlNode, parent, index = 0, transpileNode) {
|
|
8
|
-
function mapAttributesToTest ({ attributes }) {
|
|
9
|
-
if (attributes.length === 1) {
|
|
10
|
-
if (attributes[0].key === 'true' || attributes[0].key === '{true}') {
|
|
11
|
-
return new Literal(true)
|
|
12
|
-
} else if (attributes[0].key === 'false' || attributes[0].key === '{false}') {
|
|
13
|
-
return new Literal(false)
|
|
14
|
-
} else if (isCurlyTag(attributes[0].key)) {
|
|
15
|
-
return transpileExpression(attributes[0].key)
|
|
16
|
-
} else {
|
|
17
|
-
return new Identifier({ name: attributes[0].key, parameter: true })
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw new Error('Unsupported length of attributes (if)')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function mapCurrentNodeToConsequent (htmlNode) {
|
|
24
|
-
const body = htmlNode.children.map((node, index) => transpileNode({ node, parent: htmlNode.children, index })).filter(Boolean)
|
|
25
|
-
const argument = body.pop() || new Literal('')
|
|
26
|
-
body.push(new ReturnStatement({ argument }))
|
|
27
|
-
return new BlockStatement({ body })
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function mapNextNodeToAlternate (nextNode) {
|
|
31
|
-
if (nextNode && nextNode.tagName === 'else') {
|
|
32
|
-
const body = nextNode.children.map((node, index) => transpileNode({ node, parent: nextNode.children, index })).filter(Boolean)
|
|
33
|
-
const argument = body.pop()
|
|
34
|
-
body.push(new ReturnStatement({ argument }))
|
|
35
|
-
return new BlockStatement({ body })
|
|
36
|
-
} else if (nextNode && nextNode.tagName === 'elseif') {
|
|
37
|
-
return mapIfStatement(nextNode, parent, index + 1, transpileNode)
|
|
38
|
-
}
|
|
39
|
-
return new BlockStatement({
|
|
40
|
-
body: [
|
|
41
|
-
new ReturnStatement({
|
|
42
|
-
argument: new Literal('')
|
|
43
|
-
})
|
|
44
|
-
]
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return new IfStatement({
|
|
49
|
-
test: mapAttributesToTest(htmlNode),
|
|
50
|
-
consequent: mapCurrentNodeToConsequent(htmlNode),
|
|
51
|
-
alternate: mapNextNodeToAlternate(parent[index + 1])
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = mapIfStatement
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
import: require('./import'),
|
|
3
|
-
doctype: require('./doctype'),
|
|
4
|
-
partial: require('./partial'),
|
|
5
|
-
slot: require('./slot'),
|
|
6
|
-
for: require('./for'),
|
|
7
|
-
if: require('./if'),
|
|
8
|
-
unless: require('./unless'),
|
|
9
|
-
try: require('./try'),
|
|
10
|
-
any: require('./any'),
|
|
11
|
-
comment: require('./comment'),
|
|
12
|
-
text: require('./text')
|
|
13
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
const { findAttributeByKey } = require('../../../utilities/attributes')
|
|
3
|
-
const { pathToIdentifier } = require('../utilities/path')
|
|
4
|
-
|
|
5
|
-
const { CallExpression, Identifier } = AbstractSyntaxTree
|
|
6
|
-
|
|
7
|
-
module.exports = function partial (node) {
|
|
8
|
-
const attribute = findAttributeByKey(node.attributes, 'from')
|
|
9
|
-
const path = attribute.value
|
|
10
|
-
return new CallExpression({
|
|
11
|
-
callee: new Identifier({
|
|
12
|
-
name: pathToIdentifier(path),
|
|
13
|
-
partial: true,
|
|
14
|
-
path
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
|
|
3
|
-
const { ReturnStatement, BlockStatement, TryStatement, CatchClause } = AbstractSyntaxTree
|
|
4
|
-
|
|
5
|
-
function mapTryStatement (htmlNode, parent, index, transpileNode) {
|
|
6
|
-
function mapCurrentNodeToBlockStatement (htmlNode) {
|
|
7
|
-
const body = htmlNode.children.map((node, index) => transpileNode({ node, parent: htmlNode.children, index })).filter(Boolean)
|
|
8
|
-
const argument = body.pop()
|
|
9
|
-
body.push(new ReturnStatement({ argument }))
|
|
10
|
-
return new BlockStatement({ body })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function mapNextNodeToCatchClause (nextNode) {
|
|
14
|
-
if (nextNode && nextNode.tagName === 'catch') {
|
|
15
|
-
const body = nextNode.children.map((node, index) => transpileNode({ node, parent: htmlNode.children, index })).filter(Boolean)
|
|
16
|
-
const argument = body.pop()
|
|
17
|
-
body.push(new ReturnStatement({ argument }))
|
|
18
|
-
return new CatchClause({
|
|
19
|
-
body: new BlockStatement({ body })
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
return new TryStatement({
|
|
25
|
-
block: mapCurrentNodeToBlockStatement(htmlNode),
|
|
26
|
-
handler: mapNextNodeToCatchClause(parent[index + 1])
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = mapTryStatement
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const AbstractSyntaxTree = require('abstract-syntax-tree')
|
|
2
|
-
const ifTag = require('./if')
|
|
3
|
-
|
|
4
|
-
const { Identifier, Literal, IfStatement, ReturnStatement, BlockStatement, UnaryExpression } = AbstractSyntaxTree
|
|
5
|
-
|
|
6
|
-
function mapUnlessStatement (htmlNode, parent, index, transpileNode) {
|
|
7
|
-
function mapAttributesToTest ({ attributes }) {
|
|
8
|
-
if (attributes.length === 1) {
|
|
9
|
-
if (attributes[0].key === 'true' || attributes[0].key === '{true}') {
|
|
10
|
-
return new Literal(true)
|
|
11
|
-
} else if (attributes[0].key === 'false' || attributes[0].key === '{false}') {
|
|
12
|
-
return new Literal(false)
|
|
13
|
-
} else {
|
|
14
|
-
return new Identifier({ name: attributes[0].key, parameter: true })
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
throw new Error('Unsupported length of attributes (unless)')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function mapCurrentNodeToConsequent (htmlNode) {
|
|
21
|
-
const body = htmlNode.children.map((node, index) => transpileNode({ node, parent: htmlNode.children, index })).filter(Boolean)
|
|
22
|
-
const argument = body.pop()
|
|
23
|
-
body.push(new ReturnStatement({ argument }))
|
|
24
|
-
return new BlockStatement({ body })
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function mapNextNodeToAlternate (nextNode) {
|
|
28
|
-
if (nextNode && nextNode.tagName === 'else') {
|
|
29
|
-
const body = nextNode.children.map((node, index) => transpileNode({ node, parent: nextNode.children, index })).filter(Boolean)
|
|
30
|
-
const argument = body.pop()
|
|
31
|
-
body.push(new ReturnStatement({ argument }))
|
|
32
|
-
return new BlockStatement({ body })
|
|
33
|
-
} else if (nextNode && nextNode.tagName === 'elseunless') {
|
|
34
|
-
return mapUnlessStatement(nextNode, parent, index + 1, transpileNode)
|
|
35
|
-
} else if (nextNode && nextNode.tagName === 'elseif') {
|
|
36
|
-
return ifTag(nextNode, parent, index + 1, transpileNode)
|
|
37
|
-
}
|
|
38
|
-
return new BlockStatement({
|
|
39
|
-
body: [
|
|
40
|
-
new ReturnStatement({
|
|
41
|
-
argument: new Literal('')
|
|
42
|
-
})
|
|
43
|
-
]
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return new IfStatement({
|
|
48
|
-
test: new UnaryExpression({
|
|
49
|
-
operator: '!',
|
|
50
|
-
argument: mapAttributesToTest(htmlNode),
|
|
51
|
-
prefix: true
|
|
52
|
-
}),
|
|
53
|
-
consequent: mapCurrentNodeToConsequent(htmlNode),
|
|
54
|
-
alternate: mapNextNodeToAlternate(parent[index + 1])
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = mapUnlessStatement
|