aboutsummaryrefslogtreecommitdiff
path: root/node_modules/acorn-dynamic-import/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/acorn-dynamic-import/src
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/acorn-dynamic-import/src')
-rw-r--r--node_modules/acorn-dynamic-import/src/index.js4
-rw-r--r--node_modules/acorn-dynamic-import/src/inject.js50
2 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/acorn-dynamic-import/src/index.js b/node_modules/acorn-dynamic-import/src/index.js
new file mode 100644
index 000000000..6eb1d4140
--- /dev/null
+++ b/node_modules/acorn-dynamic-import/src/index.js
@@ -0,0 +1,4 @@
+import * as acorn from 'acorn';
+import inject from './inject';
+
+export default inject(acorn);
diff --git a/node_modules/acorn-dynamic-import/src/inject.js b/node_modules/acorn-dynamic-import/src/inject.js
new file mode 100644
index 000000000..7a666b278
--- /dev/null
+++ b/node_modules/acorn-dynamic-import/src/inject.js
@@ -0,0 +1,50 @@
+/* eslint-disable no-underscore-dangle */
+
+export default function injectDynamicImport(acorn) {
+ const tt = acorn.tokTypes;
+
+ // NOTE: This allows `yield import()` to parse correctly.
+ tt._import.startsExpr = true;
+
+ function parseDynamicImport() {
+ const node = this.startNode();
+ this.next();
+ if (this.type !== tt.parenL) {
+ this.unexpected();
+ }
+ return this.finishNode(node, 'Import');
+ }
+
+ function peekNext() {
+ return this.input[this.pos];
+ }
+
+ // eslint-disable-next-line no-param-reassign
+ acorn.plugins.dynamicImport = function dynamicImportPlugin(instance) {
+ instance.extend('parseStatement', nextMethod => (
+ function parseStatement(...args) {
+ const node = this.startNode();
+ if (this.type === tt._import) {
+ const nextToken = peekNext.call(this);
+ if (nextToken === tt.parenL.label) {
+ const expr = this.parseExpression();
+ return this.parseExpressionStatement(node, expr);
+ }
+ }
+
+ return nextMethod.apply(this, args);
+ }
+ ));
+
+ instance.extend('parseExprAtom', nextMethod => (
+ function parseExprAtom(refDestructuringErrors) {
+ if (this.type === tt._import) {
+ return parseDynamicImport.call(this);
+ }
+ return nextMethod.call(this, refDestructuringErrors);
+ }
+ ));
+ };
+
+ return acorn;
+}