Skip to content

Commit 896057a

Browse files
committed
fix: replace deprecated cherow with @babel/parser (in estree mode)
1 parent eea625a commit 896057a

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

lib/ensure-parser-set.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1-
const {parse} = require('cherow');
1+
const {parse} = require('@babel/parser');
22
const astMatcher = require('ast-matcher');
33

44
function _parser (contents) {
55
// Turn on range to get position info in scope analysis.
66
// Do not need to turn on JSX, dumber is designed to be
77
// small, supposes to be used after transpiling.
8-
return parse(contents, {ranges: true, loc: true, module: true, next: true});
8+
const file = parse(contents, {sourceType: 'module', plugins: [
9+
// 'jsx',
10+
// 'typescript',
11+
'asyncGenerators',
12+
'bigInt',
13+
'classProperties',
14+
'classPrivateProperties',
15+
'classPrivateMethods',
16+
'decorators-legacy',
17+
// ['decorators', {'decoratorsBeforeExport': true}],
18+
'doExpressions',
19+
'dynamicImport',
20+
'exportDefaultFrom',
21+
'exportNamespaceFrom',
22+
'functionBind',
23+
'functionSent',
24+
'importMeta',
25+
'logicalAssignment',
26+
'nullishCoalescingOperator',
27+
'numericSeparator',
28+
'objectRestSpread',
29+
'optionalCatchBinding',
30+
'optionalChaining',
31+
'partialApplication',
32+
// ['pipelineOperator', {proposal: 'minimal'}],
33+
'throwExpressions',
34+
'estree' // VERY IMPORTANT to be compatible with ast-matcher
35+
]});
36+
return file && file.program;
937
}
1038

1139
module.exports = function() {

lib/transformers/name-amd-define.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function ensureNamedDefine(unit) {
9898

9999
let namedDefine;
100100
let needsScanDeps = true;
101-
let firstArgLoc = args[0].start; // .start for cherow, .range[0] for esprima
101+
let firstArgLoc = args[0].start;
102102

103103
if (args[0].type === 'Literal') {
104104
// already has named define
@@ -169,7 +169,7 @@ function ensureNamedDefine(unit) {
169169
}
170170

171171
if (cjsDeps.length) {
172-
m.insert(factory.start, depsString(cjsDeps) + ','); // .start for cherow, .range[0], for esprima
172+
m.insert(factory.start, depsString(cjsDeps) + ',');
173173
}
174174
}
175175

lib/transformers/replace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ module.exports = function(unit) {
5353

5454
if (node.value !== dep) {
5555
m.replace(
56-
node.start, // .start for cherow, .range[0] for esprima
57-
node.end, // .end cherow, .range[1] for esprima
56+
node.start,
57+
node.end,
5858
`'${dep}'`
5959
);
6060
}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@
4848
"@babel/plugin-transform-modules-commonjs": "^7.5.0",
4949
"ast-matcher": "^1.0.4",
5050
"base64-arraybuffer": "^0.2.0",
51-
"cherow": "^1.6.9",
5251
"convert-source-map": "^1.6.0",
53-
"del": "^5.0.0",
52+
"del": "^5.1.0",
5453
"dumber-module-loader": "^0.18.0",
5554
"escope": "^3.6.0",
5655
"mkdirp": "^0.5.1",
5756
"modify-code": "^0.5.3",
5857
"node-fetch": "^2.6.0",
5958
"node-libs-browser": "^2.2.1",
6059
"readable-stream": "^2.3.6",
61-
"resolve": "^1.11.1",
60+
"resolve": "^1.12.0",
6261
"source-map": "^0.7.3"
6362
},
6463
"devDependencies": {
65-
"browserify": "^16.3.0",
66-
"eslint": "^6.1.0",
64+
"@babel/parser": "^7.5.5",
65+
"browser-do": "^0.3.2",
66+
"browserify": "^16.5.0",
67+
"eslint": "^6.2.2",
6768
"nyc": "^14.1.1",
6869
"sourcemap-codec": "^1.4.6",
6970
"standard-changelog": "^2.0.13",
7071
"tap-dot": "^2.0.0",
71-
"tape": "^4.11.0",
72-
"browser-do": "^0.3.2"
72+
"tape": "^4.11.0"
7373
}
7474
}

0 commit comments

Comments
 (0)