Skip to content

Commit

Permalink
fix: fix compatibility issue with @babel/parser
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Aug 29, 2019
1 parent 49ff738 commit 1de4b92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const STOP = false;
const SKIP_BRANCH = 1;

// ignore position info, and raw
const IGNORED_KEYS = ['start', 'end', 'loc', 'location', 'locations', 'line', 'column', 'range', 'ranges', 'raw'];
const IGNORED_KEYS = ['start', 'end', 'loc', 'location', 'locations', 'line', 'column', 'range', 'ranges', 'raw', 'extra'];

let parser = function() {
throw new Error('No parser set, you need to set parser before use astMatcher. For instance, astMatcher.setParser(esprima.parse)');
Expand Down
23 changes: 23 additions & 0 deletions spec/with-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ module.exports = function (parserName, parser) {
'(__any, __any.noView)([__arr_deps], __str_baseUrl)',
'(1, _aureliaFramework.noView)(["./foo", "./bar"], "lorem")'
), {deps: ['./foo', './bar'], baseUrl: 'lorem'});
t.deepEqual(extractTest(
'(__any, __any.noView)([__arr_deps])',
'(1, _aureliaFramework.noView)(["./foo", "./bar"])'
), {deps: ['./foo', './bar']});
t.deepEqual(extractTest(
'(__any, __any.useView)(__arr_dep)',
'(1, _aureliaFramework.useView)("./foo.html")'
), {dep: ['./foo.html']});
t.end();
});

Expand Down Expand Up @@ -269,6 +277,21 @@ module.exports = function (parserName, parser) {
t.end();
});

testP('matcher built by astMatcher complex pattern', t => {
const m = astMatcher('(__any, __any.noView)([__arr_deps])');
const r = m('(dec = (1, _aureliaFramework.noView)(["./foo", "./bar"]), dec())');
t.ok(r);
t.equal(r.length, 1);
t.deepEqual(r[0].match.deps, ["./foo", "./bar"]);

const m2 = astMatcher('(__any, __any.useView)(__arr_dep)');
const r2 = m2('(dec = (1, _aureliaFramework.useView)("./foo.html"), dec())');
t.ok(r2);
t.equal(r2.length, 1);
t.deepEqual(r2[0].match.dep, ['./foo.html']);
t.end();
});

if (parserName === 'cherow') {
testP('matcher built by astMatcher supports class body with __anl', t => {
let m = astMatcher('export class __any_name { __anl_body }');
Expand Down

0 comments on commit 1de4b92

Please sign in to comment.