refactor(compiler): switch to acorn

This commit is contained in:
Evan You 2019-10-02 11:05:56 -04:00
parent 9c9dd73017
commit b33f0ceff1
4 changed files with 6 additions and 11 deletions

View File

@ -345,6 +345,6 @@ describe('compiler: expression transform', () => {
test('should handle parse error', () => {
const onError = jest.fn()
parseWithExpressionTransform(`{{ a( }}`, { onError })
expect(onError.mock.calls[0][0].message).toMatch(`Expected ')'`)
expect(onError.mock.calls[0][0].message).toMatch(`Unexpected token (1:4)`)
})
})

View File

@ -28,8 +28,8 @@
},
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-core#readme",
"dependencies": {
"acorn": "^7.1.0",
"estree-walker": "^0.8.1",
"meriyah": "^1.7.2",
"source-map": "^0.7.3"
}
}

View File

@ -1,19 +1,19 @@
import { SourceLocation, Position, ElementNode, NodeTypes } from './ast'
import { parseScript } from 'meriyah'
import { parse } from 'acorn'
import { walk } from 'estree-walker'
// cache node requires
// lazy require dependencies so that they don't end up in rollup's dep graph
// and thus can be tree-shaken in browser builds.
let _parseScript: typeof parseScript
let _parse: typeof parse
let _walk: typeof walk
export const parseJS: typeof parseScript = (code: string, options: any) => {
export const parseJS: typeof parse = (code: string, options: any) => {
assert(
!__BROWSER__,
`Expression AST analysis can only be performed in non-browser builds.`
)
const parse = _parseScript || (_parseScript = require('meriyah').parseScript)
const parse = _parse || (_parse = require('acorn').parse)
return parse(code, options)
}

View File

@ -4780,11 +4780,6 @@ merge2@^1.2.3:
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.4.tgz#c9269589e6885a60cf80605d9522d4b67ca646e3"
integrity sha512-FYE8xI+6pjFOhokZu0We3S5NKCirLbCzSh2Usf3qEyr4X8U+0jNg9P8RZ4qz+V2UoECLVwSyzU3LxXBaLGtD3A==
meriyah@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/meriyah/-/meriyah-1.7.2.tgz#c47d07d8f1284577658827cd134b180e80ae4bef"
integrity sha512-bBXN6hJ9RHA0mEae5O2Ocr6giK0S87nsz/W7tnBRm4kpW04LEEpXSOfwaID9GZgPRVcn3rAHzHHDDD68DLQgWw==
micromatch@^3.1.10, micromatch@^3.1.4:
version "3.1.10"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"