Skip to content

Commit

Permalink
Switch back to acorn for JS tokenization
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadKillingsworth committed Mar 8, 2017
1 parent ac16e13 commit cd0a196
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"polymer-bundler": "lib/bin/polymer-bundler.js"
},
"dependencies": {
"acorn": "4.0.4",
"clone": "^2.1.0",
"command-line-args": "^3.0.1",
"command-line-usage": "^3.0.3",
Expand All @@ -27,6 +28,7 @@
"source-map": "^0.5.6"
},
"devDependencies": {
"@types/acorn": "^4.0.1",
"@types/chai": "^3.4.30",
"@types/clone": "^0.1.30",
"@types/mocha": "^2.2.29",
Expand Down
12 changes: 6 additions & 6 deletions src/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* http://polymer.github.io/PATENTS.txt
*/

import * as acorn from 'acorn';
import * as dom5 from 'dom5';
import * as espree from 'espree';
import * as parse5 from 'parse5';
import {Analyzer} from 'polymer-analyzer';
import {AnalysisContext} from 'polymer-analyzer/lib/core/analysis-context';
Expand Down Expand Up @@ -50,9 +50,9 @@ function createJsIdentitySourcemap(
lineOffset: number,
firstLineCharOffset: number) {
const generator = new SourceMapGenerator();
const tokens =
espree.tokenize(sourceContent, {loc: true} as espree.ParseOpts);
tokens.forEach(token => {
const tokenizer = acorn.tokenizer(sourceContent, {locations: true});
for (let token = tokenizer.getToken(); token.type.label !== 'eof';
token = tokenizer.getToken()) {
if (!token.loc) {
return null;
}
Expand All @@ -66,12 +66,12 @@ function createJsIdentitySourcemap(
source: sourceUrl
};

if (token.type === 'Identifier') {
if (token.type.label === 'name') {
mapping.name = token.value;
}

generator.addMapping(mapping);
});
}

return generator.toJSON();
}
Expand Down

0 comments on commit cd0a196

Please sign in to comment.