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.
Files changed (139) hide show
  1. package/README.md +0 -358
  2. package/index.js +402 -4
  3. package/package.json +12 -37
  4. package/src/Bundler.js +0 -13
  5. package/src/Cache.js +0 -35
  6. package/src/Compiler.js +0 -28
  7. package/src/Importer.js +0 -142
  8. package/src/Optimizer.js +0 -96
  9. package/src/Scope.js +0 -20
  10. package/src/Statistics.js +0 -58
  11. package/src/bundlers/esbuild/index.js +0 -55
  12. package/src/bundlers/esbuild/plugins/css.js +0 -40
  13. package/src/bundlers/esbuild/plugins/html.js +0 -27
  14. package/src/bundlers/esbuild/plugins/image.js +0 -38
  15. package/src/bundlers/esbuild/plugins/resolve.js +0 -11
  16. package/src/bundlers/esbuild/plugins/yaml.js +0 -38
  17. package/src/bundlers/esbuild/utilities/asset.js +0 -19
  18. package/src/bundlers/rollup.js +0 -38
  19. package/src/compile.js +0 -6
  20. package/src/compilers/any/Compiler.js +0 -16
  21. package/src/compilers/compile.js +0 -17
  22. package/src/compilers/html/Analyzer.js +0 -24
  23. package/src/compilers/html/Compiler.js +0 -47
  24. package/src/compilers/html/Generator.js +0 -19
  25. package/src/compilers/html/Parser.js +0 -11
  26. package/src/compilers/html/Preprocessor.js +0 -130
  27. package/src/compilers/html/Renderer.js +0 -167
  28. package/src/compilers/html/Transpiler.js +0 -76
  29. package/src/compilers/js/Bundler.js +0 -84
  30. package/src/compilers/js/Compiler/index.js +0 -27
  31. package/src/conditions/isEqual.js +0 -5
  32. package/src/lexers/html.js +0 -49
  33. package/src/lexers/internal.js +0 -49
  34. package/src/linters/html/bracket.js +0 -36
  35. package/src/linters/html/component.js +0 -43
  36. package/src/linters/html/import.js +0 -35
  37. package/src/linters/html/index.js +0 -19
  38. package/src/linters/html/tag.js +0 -36
  39. package/src/optimizers/html.js +0 -15
  40. package/src/plugins/BoxModelPlugin/index.js +0 -109
  41. package/src/plugins/CurlyStylesPlugin/index.js +0 -39
  42. package/src/plugins/DataPlugin/index.js +0 -53
  43. package/src/plugins/InlinePlugin/css.js +0 -131
  44. package/src/plugins/InlinePlugin/index.js +0 -39
  45. package/src/plugins/InternationalizationPlugin/index.js +0 -111
  46. package/src/plugins/Plugin.js +0 -22
  47. package/src/plugins/ScopedStylesPlugin/css.js +0 -56
  48. package/src/plugins/ScopedStylesPlugin/html.js +0 -112
  49. package/src/plugins/ScopedStylesPlugin/index.js +0 -48
  50. package/src/plugins/SwappedStylesPlugin/index.js +0 -20
  51. package/src/render.js +0 -48
  52. package/src/tags/case.js +0 -28
  53. package/src/tags/catch.js +0 -17
  54. package/src/tags/data.js +0 -7
  55. package/src/tags/default.js +0 -20
  56. package/src/tags/doctype.js +0 -8
  57. package/src/tags/else.js +0 -18
  58. package/src/tags/elseif.js +0 -25
  59. package/src/tags/elseunless.js +0 -30
  60. package/src/tags/font.js +0 -37
  61. package/src/tags/for.js +0 -90
  62. package/src/tags/foreach.js +0 -80
  63. package/src/tags/if.js +0 -19
  64. package/src/tags/img.js +0 -25
  65. package/src/tags/index.js +0 -53
  66. package/src/tags/link.js +0 -14
  67. package/src/tags/script/index.js +0 -83
  68. package/src/tags/script/scoped.js +0 -26
  69. package/src/tags/slot.js +0 -9
  70. package/src/tags/style.js +0 -9
  71. package/src/tags/switch.js +0 -13
  72. package/src/tags/template.js +0 -22
  73. package/src/tags/translate.js +0 -22
  74. package/src/tags/translation.js +0 -38
  75. package/src/tags/try.js +0 -17
  76. package/src/tags/unless.js +0 -24
  77. package/src/tags/var.js +0 -32
  78. package/src/transpilers/css/index.js +0 -34
  79. package/src/transpilers/html/expression.js +0 -101
  80. package/src/transpilers/html/index.js +0 -189
  81. package/src/transpilers/html/node.js +0 -46
  82. package/src/transpilers/html/tags/any.js +0 -53
  83. package/src/transpilers/html/tags/comment.js +0 -7
  84. package/src/transpilers/html/tags/doctype.js +0 -6
  85. package/src/transpilers/html/tags/for.js +0 -30
  86. package/src/transpilers/html/tags/if.js +0 -55
  87. package/src/transpilers/html/tags/import.js +0 -7
  88. package/src/transpilers/html/tags/index.js +0 -13
  89. package/src/transpilers/html/tags/partial.js +0 -17
  90. package/src/transpilers/html/tags/slot.js +0 -7
  91. package/src/transpilers/html/tags/text.js +0 -6
  92. package/src/transpilers/html/tags/try.js +0 -30
  93. package/src/transpilers/html/tags/unless.js +0 -58
  94. package/src/transpilers/html/utilities/path.js +0 -9
  95. package/src/utilities/action.js +0 -208
  96. package/src/utilities/array.js +0 -80
  97. package/src/utilities/assets.js +0 -18
  98. package/src/utilities/ast.js +0 -13
  99. package/src/utilities/attributes.js +0 -23
  100. package/src/utilities/collect.js +0 -404
  101. package/src/utilities/conditions.js +0 -159
  102. package/src/utilities/convert.js +0 -359
  103. package/src/utilities/data.js +0 -55
  104. package/src/utilities/enum.js +0 -103
  105. package/src/utilities/errors.js +0 -96
  106. package/src/utilities/factory.js +0 -237
  107. package/src/utilities/files.js +0 -55
  108. package/src/utilities/filters.js +0 -140
  109. package/src/utilities/globals.js +0 -43
  110. package/src/utilities/html.js +0 -60
  111. package/src/utilities/inline.js +0 -200
  112. package/src/utilities/js.js +0 -15
  113. package/src/utilities/keywords.js +0 -35
  114. package/src/utilities/log.js +0 -31
  115. package/src/utilities/node.js +0 -149
  116. package/src/utilities/object.js +0 -8
  117. package/src/utilities/optimize.js +0 -268
  118. package/src/utilities/options.js +0 -99
  119. package/src/utilities/request.js +0 -13
  120. package/src/utilities/string.js +0 -144
  121. package/src/utilities/style.js +0 -15
  122. package/src/utilities/translations.js +0 -78
  123. package/src/utilities/url.js +0 -24
  124. package/src/vdom/browser/app.js +0 -19
  125. package/src/vdom/browser/diff.js +0 -104
  126. package/src/vdom/browser/index.js +0 -15
  127. package/src/vdom/browser/mount.js +0 -10
  128. package/src/vdom/browser/render.js +0 -66
  129. package/src/vdom/browser/replace.js +0 -7
  130. package/src/vdom/node.js +0 -10
  131. package/src/vdom/nodes.js +0 -116
  132. package/src/vdom/server/State.js +0 -21
  133. package/src/vdom/server/boxwood.js +0 -5
  134. package/src/vdom/server/index.js +0 -19
  135. package/src/vdom/server/render.js +0 -66
  136. package/src/vdom/tag.js +0 -33
  137. package/src/vdom/utilities/classes.js +0 -22
  138. package/src/vdom/utilities/css.js +0 -17
  139. package/src/vdom/utilities/escape.js +0 -50
package/src/Optimizer.js DELETED
@@ -1,96 +0,0 @@
1
- 'use strict'
2
-
3
- const { TEMPLATE_VARIABLE } = require('./utilities/enum')
4
- const {
5
- match,
6
- memberExpressionReduction,
7
- logicalExpressionReduction,
8
- binaryExpressionReduction,
9
- ternaryOperatorReduction,
10
- ifStatementRemoval
11
- } = require('abstract-syntax-tree')
12
-
13
- function isAssignmentExpressionWithLiteral (node) {
14
- return isAssignmentExpression(node) && node.expression.right.type === 'Literal'
15
- }
16
-
17
- function isAssignmentExpression (node) {
18
- return node && match(node, 'ExpressionStatement[expression.type="AssignmentExpression"]')
19
- }
20
-
21
- function isTemplateVariableDeclaration (node) {
22
- return node && node.type === 'VariableDeclaration' && node.declarations[0].id.name === TEMPLATE_VARIABLE
23
- }
24
-
25
- class Optimizer {
26
- optimize (tree) {
27
- // can the below be done in one walk?
28
- tree.replace({ enter: memberExpressionReduction })
29
- tree.replace({ enter: logicalExpressionReduction })
30
- tree.replace({ enter: binaryExpressionReduction })
31
- tree.replace({ enter: ternaryOperatorReduction })
32
- tree.replace({ enter: ifStatementRemoval })
33
- this.concatenateLiterals(tree)
34
- this.concatenateAssignmentExpressions(tree)
35
- this.simplifyReturnValue(tree)
36
- }
37
-
38
- concatenateLiterals (tree) {
39
- tree.walk(node => {
40
- if (node.body && node.body.reduce) {
41
- node.body = node.body.reduce((result, leaf) => {
42
- const last = result[result.length - 1]
43
- if (isAssignmentExpressionWithLiteral(leaf)) {
44
- if (isTemplateVariableDeclaration(last)) {
45
- last.declarations[0].init.value += leaf.expression.right.value
46
- } else if (isAssignmentExpressionWithLiteral(last)) {
47
- last.expression.right.value += leaf.expression.right.value
48
- } else {
49
- result.push(leaf)
50
- }
51
- } else {
52
- result.push(leaf)
53
- }
54
- return result
55
- }, [])
56
- }
57
- })
58
- }
59
-
60
- concatenateAssignmentExpressions (tree) {
61
- tree.walk(node => {
62
- if (node.body && node.body.reduce) {
63
- node.body = node.body.reduce((result, leaf) => {
64
- // add below code when empty statements are removed properly
65
- // const last = result[result.length - 1]
66
- // if (isAssignmentExpression(leaf)) {
67
- // if (isAssignmentExpression(last)) {
68
- // last.expression.right = {
69
- // type: "BinaryExpression",
70
- // left: last.expression.right,
71
- // right: leaf.expression.right,
72
- // operator: "+"
73
- // }
74
- // } else {
75
- // result.push(leaf)
76
- // }
77
- // } else {
78
- // result.push(leaf)
79
- // }
80
- result.push(leaf)
81
- return result
82
- }, [])
83
- }
84
- })
85
- }
86
-
87
- simplifyReturnValue (tree) {
88
- const { body } = tree
89
- if (body.length === 2) {
90
- const { value } = body[0].declarations[0].init
91
- tree.body = [{ type: 'ReturnStatement', argument: { type: 'Literal', value } }]
92
- }
93
- }
94
- }
95
-
96
- module.exports = Optimizer
package/src/Scope.js DELETED
@@ -1,20 +0,0 @@
1
- const { replace } = require('abstract-syntax-tree')
2
- const { OBJECT_VARIABLE } = require('./utilities/enum')
3
- const { isGlobalVariable } = require('./utilities/globals')
4
-
5
- class Scope {
6
- flatten (tree) {
7
- replace(tree, node => {
8
- if (isGlobalVariable(node)) {
9
- return {
10
- type: 'MemberExpression',
11
- object: { type: 'Identifier', name: OBJECT_VARIABLE },
12
- property: node.property,
13
- computed: node.computed
14
- }
15
- }
16
- })
17
- }
18
- }
19
-
20
- module.exports = Scope
package/src/Statistics.js DELETED
@@ -1,58 +0,0 @@
1
- 'use strict'
2
-
3
- // TODO pure-utilities unique should work for objects
4
- function uniq (array) {
5
- // @ts-ignore
6
- return Array.from(new Set(array.map(item => JSON.stringify(item)))).map(JSON.parse)
7
- }
8
-
9
- class Statistics {
10
- constructor () {
11
- this.components = []
12
- this.partials = []
13
- this.images = []
14
- this.scripts = []
15
- this.stylesheets = []
16
- this.translations = []
17
- }
18
-
19
- concat (name, array) {
20
- this[name] = this[name].concat(array)
21
- return this
22
- }
23
-
24
- merge (statistics) {
25
- this
26
- .concat('components', statistics.components)
27
- .concat('partials', statistics.partials)
28
- .concat('images', statistics.images)
29
- .concat('scripts', statistics.scripts)
30
- .concat('stylesheets', statistics.stylesheets)
31
- .concat('translations', statistics.translations)
32
- }
33
-
34
- assets () {
35
- return uniq([].concat(
36
- this.components.map(item => item.path),
37
- this.partials.map(item => item.path),
38
- this.images.map(item => item.path),
39
- this.scripts.map(item => item.path),
40
- this.stylesheets.map(item => item.path),
41
- this.translations.map(item => item.path)
42
- ))
43
- }
44
-
45
- serialize () {
46
- return {
47
- components: uniq(this.components),
48
- partials: uniq(this.partials),
49
- images: uniq(this.images),
50
- scripts: uniq(this.scripts),
51
- stylesheets: uniq(this.stylesheets),
52
- translations: uniq(this.translations),
53
- assets: this.assets()
54
- }
55
- }
56
- }
57
-
58
- module.exports = Statistics
@@ -1,55 +0,0 @@
1
- const esbuild = require('esbuild')
2
- const AbstractSyntaxTree = require('abstract-syntax-tree')
3
- const { writeFileSync, unlinkSync } = require('fs')
4
- const { join } = require('path')
5
- const { tmpdir } = require('os')
6
- const { uid } = require('pure-utilities/string')
7
- const ResolvePlugin = require('./plugins/resolve')
8
- const HTMLPlugin = require('./plugins/html')
9
- const CSSPlugin = require('./plugins/css')
10
- const YAMLPlugin = require('./plugins/yaml')
11
- const ImagePlugin = require('./plugins/image')
12
-
13
- const bundle = async (source, options = {}) => {
14
- const paths = options.paths || []
15
- const styles = []
16
- const input = join(tmpdir(), `${uid()}.js`)
17
-
18
- writeFileSync(input, source)
19
- const result = await esbuild.build({
20
- platform: options.platform || 'node',
21
- bundle: true,
22
- plugins: [
23
- ResolvePlugin({ paths }),
24
- HTMLPlugin({ paths }),
25
- CSSPlugin({ paths, styles }),
26
- YAMLPlugin({ paths }),
27
- ImagePlugin({ paths })
28
- ],
29
- entryPoints: [input],
30
- format: options.format || 'iife',
31
- minify: false,
32
- write: false,
33
- target: 'es2016'
34
- })
35
- const file = result.outputFiles[0]
36
- unlinkSync(input)
37
- const tree = new AbstractSyntaxTree(file.text)
38
- tree.replace(node => {
39
- // TODO we need a better way to match the global scoped style tag
40
- // this could lead to false
41
- if (
42
- node.type === 'ObjectExpression' &&
43
- node.properties.length === 1 &&
44
- node.properties[0].type === 'Property' &&
45
- node.properties[0].key.type === 'Identifier' &&
46
- node.properties[0].key.name === 'scoped'
47
- ) {
48
- return { type: 'Literal', value: styles.join(' ') }
49
- }
50
- return node
51
- })
52
- return tree.source
53
- }
54
-
55
- module.exports = { bundle }
@@ -1,40 +0,0 @@
1
- const { promises: { readFile } } = require('fs')
2
- const { findAsset } = require('../utilities/asset')
3
- const { transpile: transpileCSS, getSelectors } = require('../../../transpilers/css')
4
-
5
- module.exports = ({ paths, styles }) => ({
6
- name: 'css',
7
- setup (build) {
8
- build.onResolve({ filter: /\.css/ }, args => ({
9
- path: args.path,
10
- namespace: 'boxwood-css'
11
- }))
12
- build.onLoad({
13
- filter: /.*/,
14
- namespace: 'boxwood-css'
15
- }, async (args) => {
16
- const hasParams = args.path.includes('?')
17
- const isScoped = hasParams && args.path.includes('scoped=true')
18
- const path = hasParams ? args.path.substring(0, args.path.indexOf('?')) : args.path
19
- const asset = findAsset(path, 'css', { paths })
20
- if (!asset) {
21
- // throw with a nice error message and add specs
22
- }
23
- const content = await readFile(asset.path, 'utf8')
24
- if (isScoped) {
25
- const style = transpileCSS(content)
26
- const selectors = getSelectors(style)
27
- styles.push(style)
28
- return {
29
- contents: `export default ${JSON.stringify(selectors)}`,
30
- loader: 'js'
31
- }
32
- } else {
33
- return {
34
- contents: `export default \`${content}\``,
35
- loader: 'js'
36
- }
37
- }
38
- })
39
- }
40
- })
@@ -1,27 +0,0 @@
1
- const { promises: { readFile } } = require('fs')
2
- const { findAsset } = require('../utilities/asset')
3
- const { transpile: transpileHTML } = require('../../../transpilers/html')
4
-
5
- module.exports = ({ paths }) => ({
6
- name: 'html',
7
- setup (build) {
8
- build.onResolve({ filter: /\.html?$/ }, args => ({
9
- path: args.path.replace(/\.html$/, ''),
10
- namespace: 'boxwood-html'
11
- }))
12
- build.onLoad({
13
- filter: /.*/,
14
- namespace: 'boxwood-html'
15
- }, async (args) => {
16
- const asset = findAsset(args.path, 'html', { paths })
17
- if (!asset) {
18
- // throw with a nice error message and add specs
19
- }
20
- const content = await readFile(asset.path, 'utf8')
21
- return {
22
- contents: transpileHTML(content.trim()),
23
- loader: 'js'
24
- }
25
- })
26
- }
27
- })
@@ -1,38 +0,0 @@
1
- const { promises: { readFile } } = require('fs')
2
- const { findAsset } = require('../utilities/asset')
3
- const { getExtension, getBase64Extension } = require('../../../utilities/string')
4
-
5
- function getBase64String (base64, path) {
6
- const extension = getExtension(path)
7
- return [
8
- `data:image/${getBase64Extension(extension)}`,
9
- 'charset=utf-8',
10
- `base64,${base64}`
11
- ].join(';')
12
- }
13
-
14
- module.exports = ({ paths }) => ({
15
- name: 'image',
16
- setup (build) {
17
- build.onResolve({ filter: /\.png|\.svg|\.jpg|\.jpeg/ }, args => ({
18
- path: args.path,
19
- namespace: 'boxwood-image'
20
- }))
21
- build.onLoad({
22
- filter: /.*/,
23
- namespace: 'boxwood-image'
24
- }, async (args) => {
25
- const asset = findAsset(args.path, null, { paths })
26
- if (!asset) {
27
- // TODO throw with a nice error message and add specs
28
- }
29
-
30
- const buffer = await readFile(asset.path)
31
- const base64 = buffer.toString('base64')
32
- return {
33
- contents: `export default "${getBase64String(base64, asset.path)}"`,
34
- loader: 'js'
35
- }
36
- })
37
- }
38
- })
@@ -1,11 +0,0 @@
1
- const { findAsset } = require('../utilities/asset')
2
-
3
- module.exports = ({ paths }) => ({
4
- name: 'resolve',
5
- setup (build) {
6
- build.onResolve({ filter: /.*/ }, args => {
7
- // TODO handle libs from node_modules out of the box
8
- return findAsset(args.path, undefined, { paths })
9
- })
10
- }
11
- })
@@ -1,38 +0,0 @@
1
- const YAML = require('yaml')
2
- const { findAsset } = require('../utilities/asset')
3
- const { promises: { readFile } } = require('fs')
4
-
5
- module.exports = ({ paths }) => ({
6
- name: 'yaml',
7
- setup (build) {
8
- build.onResolve({ filter: /\.yaml?$/ }, args => ({
9
- path: args.path.replace(/\.yaml$/, ''),
10
- namespace: 'boxwood-yaml'
11
- }))
12
- build.onLoad({
13
- filter: /.*/,
14
- namespace: 'boxwood-yaml'
15
- }, async (args) => {
16
- const asset = findAsset(args.path, 'yaml', { paths })
17
- if (!asset) {
18
- // throw with a nice error message and add specs
19
- }
20
- const content = await readFile(asset.path, 'utf8')
21
- const data = YAML.parse(content)
22
- return {
23
- contents: `
24
- const data = ${JSON.stringify(data)}
25
-
26
- export function i18n (language) {
27
- return function (key) {
28
- return data.i18n[key][language]
29
- }
30
- }
31
-
32
- export default data
33
- `,
34
- loader: 'js'
35
- }
36
- })
37
- }
38
- })
@@ -1,19 +0,0 @@
1
- const { existsSync } = require('fs')
2
- const { join } = require('path')
3
-
4
- function findAsset (filepath, extension = 'js', { paths }) {
5
- const searchPath = extension
6
- ? filepath.endsWith(`.${extension}`) ? filepath : `${filepath}.${extension}`
7
- : filepath
8
- for (let i = 0, ilen = paths.length; i < ilen; i += 1) {
9
- const path = join(paths[i], searchPath)
10
- const index = join(paths[i], filepath, `index.${extension}`)
11
- if (existsSync(path)) {
12
- return { path }
13
- } else if (extension && existsSync(index)) {
14
- return { path: index }
15
- }
16
- }
17
- }
18
-
19
- module.exports = { findAsset }
@@ -1,38 +0,0 @@
1
- // @ts-nocheck
2
-
3
- 'use strict'
4
-
5
- const AbstractSyntaxTree = require('abstract-syntax-tree')
6
- const { rollup } = require('rollup')
7
- const { nodeResolve } = require('@rollup/plugin-node-resolve')
8
- const commonjs = require('@rollup/plugin-commonjs')
9
- const paths = require('rollup-plugin-includepaths')
10
- const { writeFileSync, unlinkSync } = require('fs')
11
- const { join } = require('path')
12
- const { tmpdir } = require('os')
13
- const { uid } = require('pure-utilities/string')
14
-
15
- const bundle = async (source, options = {}) => {
16
- const tree = new AbstractSyntaxTree(source)
17
- if (tree.has('ImportDeclaration')) {
18
- const input = join(tmpdir(), `${uid()}.js`)
19
- writeFileSync(input, source)
20
- const bundle = await rollup({
21
- input,
22
- plugins: [
23
- paths({ paths: options.paths }),
24
- // TODO we could try to find closest node_modules dir here via something like find-node-modules
25
- nodeResolve(options.resolve),
26
- commonjs()
27
- ]
28
- })
29
- const { output } = await bundle.generate({ format: 'iife' })
30
- const { code } = output[0]
31
- unlinkSync(input)
32
- return code
33
- } else {
34
- return source
35
- }
36
- }
37
-
38
- module.exports = { bundle }
package/src/compile.js DELETED
@@ -1,6 +0,0 @@
1
- const Compiler = require('./Compiler')
2
-
3
- module.exports = async function compile (source, options = {}) {
4
- const compiler = new Compiler(options)
5
- return compiler.compile(source)
6
- }
@@ -1,16 +0,0 @@
1
- const JSCompiler = require('../js/Compiler')
2
- const { transpile } = require('../../transpilers/html')
3
-
4
- class Compiler {
5
- constructor (options = {}) {
6
- this.options = options
7
- }
8
-
9
- async compile (input) {
10
- const source = this.options.format === 'js' ? input : transpile(input, this.options)
11
- const compiler = new JSCompiler(this.options)
12
- return compiler.compile(source)
13
- }
14
- }
15
-
16
- module.exports = Compiler
@@ -1,17 +0,0 @@
1
- const JSCompiler = require('./js/Compiler')
2
- const HTMLCompiler = require('./html/Compiler')
3
- const AnyCompiler = require('./any/Compiler')
4
- const { getExtension } = require('../utilities/string')
5
-
6
- const compilers = {
7
- js: JSCompiler,
8
- html: HTMLCompiler,
9
- any: AnyCompiler
10
- }
11
-
12
- module.exports = async function compile (input, options) {
13
- const extension = getExtension(options.path) || 'html'
14
- const Compiler = options.compiler ? compilers[options.compiler] : compilers[extension] || compilers.html
15
- const compiler = new Compiler(options)
16
- return compiler.compile(input)
17
- }
@@ -1,24 +0,0 @@
1
- 'use strict'
2
-
3
- const { OBJECT_VARIABLE, ESCAPE_VARIABLE } = require('../../utilities/enum')
4
-
5
- class Analyzer {
6
- analyze (tree) {
7
- const params = this.deduceParams(tree)
8
- return { params }
9
- }
10
-
11
- deduceParams (tree) {
12
- // could do it more effectively by checking if given param was used at least once
13
- // instead of querying here
14
- if (tree.has(`Identifier[name="${ESCAPE_VARIABLE}"]`)) {
15
- return [OBJECT_VARIABLE, ESCAPE_VARIABLE].join(', ')
16
- } else if (tree.has(`Identifier[name="${OBJECT_VARIABLE}"]`)) {
17
- return OBJECT_VARIABLE
18
- } else {
19
- return ''
20
- }
21
- }
22
- }
23
-
24
- module.exports = Analyzer
@@ -1,47 +0,0 @@
1
- 'use strict'
2
-
3
- const Transpiler = require('./Transpiler')
4
- const Parser = require('./Parser')
5
- const Renderer = require('./Renderer')
6
- const Generator = require('./Generator')
7
- const { validateOptions } = require('../../utilities/options')
8
- const { normalizeError } = require('../../utilities/errors')
9
-
10
- const transpile = (source) => {
11
- const transpiler = new Transpiler()
12
- return transpiler.transpile(source)
13
- }
14
-
15
- const parse = (source) => {
16
- const parser = new Parser()
17
- return parser.parse(source)
18
- }
19
-
20
- const generate = async (source, html, options) => {
21
- const renderer = new Renderer()
22
- const { tree, statistics, warnings, errors } = await renderer.render(source, html, options)
23
- const generator = new Generator()
24
- const { template, dynamic } = generator.generate(tree)
25
- return {
26
- template,
27
- statistics: statistics.serialize(),
28
- errors: errors.concat(validateOptions(options)).map(normalizeError),
29
- warnings,
30
- dynamic
31
- }
32
- }
33
-
34
- class Compiler {
35
- constructor (options) {
36
- this.options = options
37
- }
38
-
39
- async compile (input) {
40
- const { options } = this
41
- const source = transpile(input)
42
- const tree = parse(source)
43
- return generate(source, tree, options)
44
- }
45
- }
46
-
47
- module.exports = Compiler
@@ -1,19 +0,0 @@
1
- 'use strict'
2
-
3
- const Analyzer = require('./Analyzer')
4
-
5
- const analyze = (tree) => {
6
- const analyzer = new Analyzer()
7
- return analyzer.analyze(tree)
8
- }
9
-
10
- class Generator {
11
- generate (tree) {
12
- const { params } = analyze(tree)
13
- const template = new Function(`return function render(${params}) {\n${tree.source}}`)() // eslint-disable-line
14
- const dynamic = params.length > 0
15
- return { template, dynamic }
16
- }
17
- }
18
-
19
- module.exports = Generator
@@ -1,11 +0,0 @@
1
- 'use strict'
2
-
3
- const { parse } = require('../../utilities/html')
4
-
5
- class Parser {
6
- parse (source) {
7
- return parse(source)
8
- }
9
- }
10
-
11
- module.exports = Parser