boxwood 0.58.1 → 0.59.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 CHANGED
@@ -11,8 +11,6 @@
11
11
  - [Install](#install)
12
12
  - [Usage](#usage)
13
13
  - [API](#api)
14
- - [Examples](#examples)
15
- - [Benchmarks](#benchmarks)
16
14
  - [REPL](https://buxlabs.pl/en/tools/js/boxwood)
17
15
  - [Maintainers](#maintainers)
18
16
  - [Contributing](#contributing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "boxwood",
3
- "version": "0.58.1",
3
+ "version": "0.59.0",
4
4
  "description": "Compile HTML templates into JS",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,14 +1,18 @@
1
1
  const AbstractSyntaxTree = require('abstract-syntax-tree')
2
2
  const Bundler = require('../Bundler')
3
3
  const { OBJECT_VARIABLE } = require('../../../utilities/enum')
4
+ const { getOptions, validateOptions } = require('../../../utilities/options')
4
5
 
5
6
  class Compiler {
6
7
  constructor (options) {
7
- this.options = options
8
+ this.options = getOptions(options)
8
9
  }
9
10
 
10
11
  async compile (input) {
11
- const bundler = new Bundler(this.options)
12
+ const { options } = this
13
+ const errors = validateOptions(options)
14
+ if (errors.length > 0) { return { errors } }
15
+ const bundler = new Bundler(options)
12
16
  const bundle = await bundler.bundle(input)
13
17
  const tree = new AbstractSyntaxTree(bundle)
14
18
  const expression = tree.first('CallExpression > ArrowFunctionExpression')
@@ -16,7 +20,7 @@ class Compiler {
16
20
  const lastNode = body.pop()
17
21
  body.push({ type: 'ReturnStatement', argument: lastNode.expression })
18
22
  const template = new Function(`return function render(${OBJECT_VARIABLE}) {\nreturn ${tree.source}}`)() // eslint-disable-line
19
- return { template }
23
+ return { template, errors: [] }
20
24
  }
21
25
  }
22
26
 
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
3
  const { parse, walk, generate } = require('css-tree')
4
- const hash = require('string-hash')
4
+ const { hash } = require('../../utilities/string')
5
5
  const { normalizeNewline } = require('../../utilities/string')
6
6
 
7
7
  function addScopeToCssSelectors (input, scopes) {
8
8
  const content = normalizeNewline(input).trim()
9
- const id = `scope-${hash(content)}`
9
+ const id = hash(content)
10
10
  const tree = parse(content)
11
11
  const keyframes = {}
12
12
  walk(tree, node => {
@@ -84,7 +84,7 @@ function transpileNode ({ node: htmlNode, parent, index }) {
84
84
  return new Identifier({ name: attributes[0].key, parameter: true })
85
85
  }
86
86
  }
87
- throw new Error('unsupported')
87
+ throw new Error('Unsupported length of attributes (if)')
88
88
  }
89
89
 
90
90
  function mapCurrentNodeToConsequent (htmlNode) {
@@ -130,7 +130,7 @@ function transpileNode ({ node: htmlNode, parent, index }) {
130
130
  return new Identifier({ name: attributes[0].key, parameter: true })
131
131
  }
132
132
  }
133
- throw new Error('unsupported')
133
+ throw new Error('Unsupported length of attributes (unless)')
134
134
  }
135
135
 
136
136
  function mapCurrentNodeToConsequent (htmlNode) {
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { extname } = require('path')
4
4
  const lexer = require('./lexer')
5
+ const stringHash = require('string-hash')
5
6
 
6
7
  function curlyTag (string) {
7
8
  return `{${string}}`
@@ -118,6 +119,11 @@ function wordsToNumbers (string) {
118
119
  if (index >= 0) { return index }
119
120
  }
120
121
 
122
+ function hash (string) {
123
+ if (!string) { return '' }
124
+ return 's' + stringHash(string).toString(16)
125
+ }
126
+
121
127
  module.exports = {
122
128
  extract,
123
129
  extractValues,
@@ -133,5 +139,6 @@ module.exports = {
133
139
  dasherize,
134
140
  hyphenate,
135
141
  wordsToNumbers,
136
- normalizeNewline
142
+ normalizeNewline,
143
+ hash
137
144
  }