Skip to content

Commit

Permalink
fix: Unexpected token when using dynamic imports (#320)
Browse files Browse the repository at this point in the history
Extended acorn parser to support dynamic imports

fixes #134 & #301
  • Loading branch information
StephanGerbeth authored and paulgv committed Jun 2, 2019
1 parent bd6b8f6 commit 7dd1dbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"dependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
"acorn": "^6.1.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-walk": "^6.1.1",
"cookie": "^0.4.0",
"js-cookie": "^2.2.0",
Expand Down
8 changes: 5 additions & 3 deletions src/helpers/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const { readFileSync } = require('fs')
const { COMPONENT_OPTIONS_KEY } = require('./constants')

const acorn = require('acorn')
const walker = require('acorn-walk')
const dynamicImport = require('acorn-dynamic-import')
const inject = require('acorn-dynamic-import/lib/walk')
const walker = inject.default(require('acorn-walk'))
// Must not be an explicit dependency to avoid version mismatch issue.
// See https://github.com/nuxt-community/nuxt-i18n/issues/297
const compiler = require('vue-template-compiler')
Expand All @@ -15,7 +17,7 @@ exports.extractComponentOptions = (path) => {
}

const script = Component.script.content
const parsed = acorn.parse(script, {
const parsed = acorn.Parser.extend(dynamicImport.default).parse(script, {
ecmaVersion: 10,
sourceType: 'module'
})
Expand All @@ -26,7 +28,7 @@ exports.extractComponentOptions = (path) => {
componentOptions = eval(`({${data}})`)[COMPONENT_OPTIONS_KEY] // eslint-disable-line
}
}
})
}, walker.base)

return componentOptions
}

0 comments on commit 7dd1dbc

Please sign in to comment.