Skip to content

Commit 3e15dae

Browse files
committed
fix(compiler): remove buggy compileSimpleExpression, add test coverage check
1 parent 625acaf commit 3e15dae

File tree

7 files changed

+18
-23
lines changed

7 files changed

+18
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jspm_packages
3535

3636
# Optional REPL history
3737
.node_repl_history
38+
39+
# reify cache for allowing import export in node
40+
.reify-cache

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "src/index.js",
77
"scripts": {
88
"build": "rollup src/index.js -f cjs -o dist/compiler.js",
9-
"test": "npm run build && mocha test",
9+
"test": "nyc --reporter=lcov --reporter=text mocha test",
1010
"lint": "standard src/* test/*"
1111
},
1212
"author": {
@@ -34,7 +34,9 @@
3434
"devDependencies": {
3535
"chai": "3.5.0",
3636
"mocha": "2.5.3",
37+
"nyc": "^10.3.2",
3738
"pre-push": "0.1.1",
39+
"reify": "^0.11.0",
3840
"rollup": "^0.41.6",
3941
"standard": "7.1.2"
4042
},
@@ -48,6 +50,7 @@
4850
},
4951
"pre-push": [
5052
"lint",
51-
"test"
53+
"test",
54+
"build"
5255
]
5356
}

src/context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ else if (typeof global !== 'undefined') globalObj = global // eslint-disable-lin
99
else if (typeof self !== 'undefined') globalObj = self // eslint-disable-line
1010
globalObj.$nxCompileToSandbox = toSandbox
1111
globalObj.$nxClearSandbox = clearSandbox
12+
globalObj.$nxGlobals = globals
1213

1314
export function expose (...globalNames) {
1415
for (let globalName of globalNames) {

src/rawCompiler.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
const isSimple = /^(\w|\.)+$/
2-
31
export function compileRawExpression (src) {
4-
return isSimple.test(src) ? compileSimpleExpression(src) : compileComplexExpression(src)
5-
}
6-
7-
function compileSimpleExpression (src) {
8-
return new Function('context', 'tempVars', // eslint-disable-line
9-
`if (tempVars) {
10-
try { return tempVars.${src} } catch (err) {
11-
if (!(err instanceof TypeError)) throw err
12-
}
13-
}
14-
try { return context.${src} } catch (err) {
15-
if (!(err instanceof TypeError)) throw err
16-
}`)
17-
}
18-
19-
function compileComplexExpression (src) {
202
return new Function('context', 'tempVars', // eslint-disable-line
213
`const sandbox = $nxCompileToSandbox(context, tempVars)
224
try { with (sandbox) { return ${src} } } catch (err) {

test/compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
22

3+
require('reify')
4+
35
const expect = require('chai').expect
4-
const compiler = require('../dist/compiler')
6+
const compiler = require('../src/index')
57

68
const localProp = 'localProp'
79
global.globalProp = 'globalProp'

test/context.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
22

3+
require('reify')
4+
35
const expect = require('chai').expect
4-
const compiler = require('../dist/compiler')
6+
const compiler = require('../src/index')
57

68
describe('context', () => {
79
afterEach(() => compiler.hideAll())

test/modifiers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict'
22

3+
require('reify')
4+
35
const expect = require('chai').expect
4-
const compiler = require('../dist/compiler')
6+
const compiler = require('../src/index')
57

68
describe('context', () => {
79
afterEach(() => compiler.hideAll())

0 commit comments

Comments
 (0)