Skip to content

Commit 52697c5

Browse files
committed
Add back acorn-dynamic-import so it can be released as nonbreaking
1 parent 885bc01 commit 52697c5

File tree

6 files changed

+92
-2
lines changed

6 files changed

+92
-2
lines changed

build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ function privateClassElements (str) {
2323
}
2424

2525
compile('acorn-bigint', './lib/bigint/index.js')
26+
compile('acorn-numeric-separator', './lib/numeric-separator/index.js')
27+
compile('acorn-dynamic-import', './lib/dynamic-import/index.js')
2628
compile('acorn-import-meta', './lib/import-meta/index.js')
2729
compile('acorn-export-ns-from', './lib/export-ns-from/index.js')
2830
compile('acorn-class-fields', './lib/class-fields/index.js', privateClassElements)
2931
compile('acorn-static-class-features', './lib/static-class-features/index.js', privateClassElements)
30-
compile('acorn-numeric-separator', './lib/numeric-separator/index.js')
3132
compile('acorn-private-class-elements', './lib/private-class-elements/index.js', function (str) {
3233
return str.replace('class extends Parser', 'class Parser_ extends Parser')
3334
})

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var CJSParser = acorn.Parser
66
.extend(require('./lib/class-fields'))
77
.extend(require('./lib/static-class-features'))
88
.extend(require('./lib/numeric-separator'))
9+
.extend(require('./lib/dynamic-import').default)
910
var ESModulesParser = CJSParser
1011
.extend(require('./lib/export-ns-from'))
1112
.extend(require('./lib/import-meta'))

lib/dynamic-import/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* Generated by `npm run build`, do not edit! */
2+
3+
'use strict';
4+
5+
Object.defineProperty(exports, "__esModule", {
6+
value: true
7+
});
8+
exports.DynamicImportKey = undefined;
9+
10+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) { descriptor.writable = true; } Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) { defineProperties(Constructor.prototype, protoProps); } if (staticProps) { defineProperties(Constructor, staticProps); } return Constructor; }; }();
11+
12+
var _get = function () {
13+
function get(object, property, receiver) { if (object === null) { object = Function.prototype; } var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }
14+
15+
return get;
16+
}();
17+
18+
exports['default'] = dynamicImport;
19+
20+
var _acorn = require('acorn');
21+
22+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23+
24+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25+
26+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) { Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } } /* eslint-disable no-underscore-dangle */
27+
28+
29+
var DynamicImportKey = exports.DynamicImportKey = 'Import';
30+
31+
// NOTE: This allows `yield import()` to parse correctly.
32+
_acorn.tokTypes._import.startsExpr = true;
33+
34+
function parseDynamicImport() {
35+
var node = this.startNode();
36+
this.next();
37+
if (this.type !== _acorn.tokTypes.parenL) {
38+
this.unexpected();
39+
}
40+
return this.finishNode(node, DynamicImportKey);
41+
}
42+
43+
function parenAfter() {
44+
return (/^(\s|\/\/.*|\/\*[^]*?\*\/)*\(/.test(this.input.slice(this.pos))
45+
);
46+
}
47+
48+
function dynamicImport(Parser) {
49+
return function (_Parser) {
50+
_inherits(_class, _Parser);
51+
52+
function _class() {
53+
_classCallCheck(this, _class);
54+
55+
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
56+
}
57+
58+
_createClass(_class, [{
59+
key: 'parseStatement',
60+
value: function () {
61+
function parseStatement(context, topLevel, exports) {
62+
if (this.type === _acorn.tokTypes._import && parenAfter.call(this)) {
63+
return this.parseExpressionStatement(this.startNode(), this.parseExpression());
64+
}
65+
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseStatement', this).call(this, context, topLevel, exports);
66+
}
67+
68+
return parseStatement;
69+
}()
70+
}, {
71+
key: 'parseExprAtom',
72+
value: function () {
73+
function parseExprAtom(refDestructuringErrors) {
74+
if (this.type === _acorn.tokTypes._import) {
75+
return parseDynamicImport.call(this);
76+
}
77+
return _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'parseExprAtom', this).call(this, refDestructuringErrors);
78+
}
79+
80+
return parseExprAtom;
81+
}()
82+
}]);
83+
84+
return _class;
85+
}(Parser);
86+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"devDependencies": {
1515
"acorn-bigint": "^0.4.0",
1616
"acorn-class-fields": "^0.3.1",
17+
"acorn-dynamic-import": "^4.0.0",
1718
"acorn-export-ns-from": "^0.1.0",
1819
"acorn-import-meta": "^1.0.0",
1920
"acorn-numeric-separator": "^0.3.0",

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ test('walk supports plugin syntax', function (t) {
143143
)
144144
t.plan(2)
145145
walk.simple(ast, {
146-
ImportExpression: function () {
146+
Import: function () {
147147
t.pass('import()')
148148
},
149149
MetaProperty: function () {

walk.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var xtend = require('xtend')
22
var walk = require('acorn-walk')
33

44
var base = xtend(walk.base)
5+
base.Import = function () {}
56

67
function simple (node, visitors, baseVisitor, state, override) {
78
return walk.simple(node, visitors, baseVisitor || base, state, override)

0 commit comments

Comments
 (0)