diff --git a/lib/parsers/gjs-parser.js b/lib/parsers/gjs-parser.js index 20b0d12fa5..0f02b9bbd5 100644 --- a/lib/parsers/gjs-parser.js +++ b/lib/parsers/gjs-parser.js @@ -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 @@ -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') + ast.body.splice(idx, 1); traverse(visitorKeys, result.ast, (path) => { const node = path.node; + node.loc = sc.originalPositionFor(node.loc); + node.range = [ + + ] if ( node.type === 'ExpressionStatement' || node.type === 'StaticBlock' || @@ -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 }); jsCode = info.output; + const sourceMap = info.map; let result = null; result = isTypescript @@ -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 }; }, diff --git a/package.json b/package.json index 212ca787e8..300c50f968 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 70f4b5a3d5..54ef6f02f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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==