Skip to content

Commit

Permalink
wip source map
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Aug 3, 2023
1 parent 0128f9c commit c168c29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
18 changes: 14 additions & 4 deletions lib/parsers/gjs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const glimmerVisitorKeys = require(path.join(
path.dirname(require.resolve('@glimmer/syntax')),
'lib/v1/visitor-keys'
)).default;
const SourceMap = require('source-map-js');
const babelParser = require('@babel/eslint-parser');
const typescriptParser = require('@typescript-eslint/parser');
// eslint-disable-next-line node/no-missing-require
Expand Down Expand Up @@ -208,9 +209,16 @@ function preprocessGlimmerTemplates(info, code) {
function convertAst(result, preprocessedResult, visitorKeys) {
const templateInfos = preprocessedResult.templateInfos;
let counter = 0;
const sc = new SourceMap.SourceMapConsumer(result.sourceMap);
result.ast.comments.push(...preprocessedResult.comments);
const idx = ast.body.findIndex(b => b.type === 'ImportDeclaration' && b.source.value === '@ember/template-compiler')

Check failure on line 214 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 16.x)

'ast' is not defined

Check failure on line 214 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 16.x)

Replace `b·=>·b.type·===·'ImportDeclaration'·&&·b.source.value·===·'@ember/template-compiler')` with `⏎····(b)·=>·b.type·===·'ImportDeclaration'·&&·b.source.value·===·'@ember/template-compiler'⏎··);`

Check failure on line 214 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'ast' is not defined

Check failure on line 214 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Replace `b·=>·b.type·===·'ImportDeclaration'·&&·b.source.value·===·'@ember/template-compiler')` with `⏎····(b)·=>·b.type·===·'ImportDeclaration'·&&·b.source.value·===·'@ember/template-compiler'⏎··);`
ast.body.splice(idx, 1);

Check failure on line 215 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 16.x)

'ast' is not defined

Check failure on line 215 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

'ast' is not defined
traverse(visitorKeys, result.ast, (path) => {
const node = path.node;
node.loc = sc.originalPositionFor(node.loc);
node.range = [

Check failure on line 219 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 16.x)

Replace `⏎⏎····]` with `];`

Check failure on line 219 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Replace `⏎⏎····]` with `];`

]
if (
node.type === 'ExpressionStatement' ||
node.type === 'StaticBlock' ||
Expand Down Expand Up @@ -276,13 +284,13 @@ function convertAst(result, preprocessedResult, visitorKeys) {
module.exports = {
parseForESLint(code, options, isTypescript) {
let jsCode = code;
const info = gts.transformForLint({
const info = gts.transform({
input: jsCode,
templateTag: 'template',
explicitMode: true,
linterMode: true,

includeSourceMaps: true

Check failure on line 290 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 16.x)

Insert `,`

Check failure on line 290 in lib/parsers/gjs-parser.js

View workflow job for this annotation

GitHub Actions / build (ubuntu, 18.x)

Insert `,`
});
jsCode = info.output;
const sourceMap = info.map;

let result = null;
result = isTypescript
Expand All @@ -295,6 +303,8 @@ module.exports = {
const { templateVisitorKeys } = preprocessedResult;
const visitorKeys = { ...result.visitorKeys, ...templateVisitorKeys };
result.isTypescript = isTypescript;
result.sourceMap = sourceMap;
result.code = code;
convertAst(result, preprocessedResult, visitorKeys);
return { ...result, visitorKeys };
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"lodash.camelcase": "^4.1.1",
"lodash.kebabcase": "^4.1.1",
"requireindex": "^1.2.0",
"snake-case": "^3.0.3"
"snake-case": "^3.0.3",
"source-map-js": "^1.0.2"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.13.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6563,7 +6563,7 @@ sort-package-json@^2.0.0:
is-plain-obj "^4.1.0"
sort-object-keys "^1.1.3"

source-map-js@^1.0.1:
source-map-js@^1.0.1, source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
Expand Down

0 comments on commit c168c29

Please sign in to comment.