ember-eslint-parser 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-eslint-parser",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "devDependencies": {
21
21
  "@babel/core": "^7.23.6",
22
- "@typescript-eslint/parser": "^6.15.0",
22
+ "@typescript-eslint/parser": "^6.21.0",
23
23
  "concurrently": "^8.2.2",
24
24
  "eslint": "^8.0.1",
25
25
  "eslint-config-prettier": "^9.1.0",
@@ -30,17 +30,17 @@
30
30
  "eslint-plugin-promise": "^6.0.0",
31
31
  "execa": "^8.0.1",
32
32
  "fs-extra": "^11.2.0",
33
- "vite": "^5.0.12",
34
- "vitest": "^1.2.2",
35
- "prettier": "^3.1.1",
33
+ "prettier": "^3.2.5",
36
34
  "publint": "^0.2.6",
37
- "release-plan": "^0.6.0",
38
- "typescript": "^5.3.3"
35
+ "release-plan": "^0.7.0",
36
+ "typescript": "^5.3.3",
37
+ "vite": "^5.0.12",
38
+ "vitest": "^1.2.2"
39
39
  },
40
40
  "dependencies": {
41
- "@babel/eslint-parser": "^7.23.3",
41
+ "@babel/eslint-parser": "7.23.10",
42
42
  "@glimmer/syntax": "^0.88.0",
43
- "@typescript-eslint/scope-manager": "^6.15.0",
43
+ "@typescript-eslint/scope-manager": "^6.21.0",
44
44
  "content-tag": "^1.2.2",
45
45
  "eslint-scope": "^7.2.2",
46
46
  "html-tags": "^3.3.1"
@@ -8,8 +8,6 @@ const {
8
8
  } = require('./ts-patch');
9
9
  const { transformForLint, preprocessGlimmerTemplates, convertAst } = require('./transforms');
10
10
 
11
- patchTs();
12
-
13
11
  /**
14
12
  * implements https://eslint.org/docs/latest/extend/custom-parsers
15
13
  * 1. transforms gts/gjs files into parseable ts/js without changing the offsets and locations around it
@@ -23,12 +21,13 @@ patchTs();
23
21
  */
24
22
  module.exports = {
25
23
  parseForESLint(code, options) {
24
+ patchTs();
26
25
  registerParsedFile(options.filePath);
27
26
  let jsCode = code;
28
27
  const info = transformForLint(code);
29
28
  jsCode = info.output;
30
29
 
31
- const isTypescript = options.filePath.endsWith('.gts');
30
+ const isTypescript = options.filePath.endsWith('.gts') || options.filePath.endsWith('.ts');
32
31
 
33
32
  let result = null;
34
33
  const filePath = options.filePath;
@@ -419,7 +419,7 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
419
419
  if (
420
420
  node.type === 'ExpressionStatement' ||
421
421
  node.type === 'StaticBlock' ||
422
- node.type === 'TaggedTemplateExpression' ||
422
+ node.type === 'TemplateLiteral' ||
423
423
  node.type === 'ExportDefaultDeclaration'
424
424
  ) {
425
425
  let range = node.range;
@@ -563,9 +563,9 @@ module.exports.transformForLint = function transformForLint(code) {
563
563
  jsCode = replaceRange(jsCode, tplInfo.range.start, tplInfo.range.end, replacementCode);
564
564
  } else {
565
565
  const tplLength = tplInfo.range.end - tplInfo.range.start;
566
- const spaces = tplLength - byteLength(content) - '""`'.length - '`'.length - backticks;
566
+ const spaces = tplLength - byteLength(content) - '`'.length - '`'.length - backticks;
567
567
  const total = content + ' '.repeat(spaces);
568
- const replacementCode = `""\`${total}\``;
568
+ const replacementCode = `\`${total}\``;
569
569
  jsCode = replaceRange(jsCode, tplInfo.range.start, tplInfo.range.end, replacementCode);
570
570
  }
571
571
  }
@@ -1,14 +1,17 @@
1
1
  const fs = require('node:fs');
2
2
  const { transformForLint } = require('./transforms');
3
- const babel = require('@babel/core');
4
3
  const { replaceRange } = require('./transforms');
5
4
 
6
- let patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser;
5
+ let patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser, isPatched;
7
6
 
8
7
  try {
9
8
  const ts = require('typescript');
10
9
  typescriptParser = require('@typescript-eslint/parser');
11
10
  patchTs = function patchTs() {
11
+ if (isPatched) {
12
+ return;
13
+ }
14
+ isPatched = true;
12
15
  const sys = { ...ts.sys };
13
16
  const newSys = {
14
17
  ...ts.sys,
@@ -32,13 +35,23 @@ try {
32
35
  content = fs.readFileSync(fileName).toString();
33
36
  }
34
37
  if (fileName.endsWith('.gts')) {
35
- content = transformForLint(content).output;
38
+ try {
39
+ content = transformForLint(content).output;
40
+ } catch (e) {
41
+ console.error('failed to transformForLint for gts processing');
42
+ console.error(e);
43
+ }
36
44
  }
37
45
  if (
38
46
  (!fileName.endsWith('.d.ts') && fileName.endsWith('.ts')) ||
39
47
  fileName.endsWith('.gts')
40
48
  ) {
41
- content = replaceExtensions(content);
49
+ try {
50
+ content = replaceExtensions(content);
51
+ } catch (e) {
52
+ console.error('failed to replace extensions for gts processing');
53
+ console.error(e);
54
+ }
42
55
  }
43
56
  return content;
44
57
  },
@@ -48,20 +61,12 @@ try {
48
61
 
49
62
  replaceExtensions = function replaceExtensions(code) {
50
63
  let jsCode = code;
51
- const babelParseResult = babel.parse(jsCode, {
52
- parserOpts: { ranges: true, plugins: ['typescript'] },
53
- });
64
+ const sourceFile = ts.createSourceFile('__x__.ts', code, ts.ScriptTarget.Latest);
54
65
  const length = jsCode.length;
55
- for (const b of babelParseResult.program.body) {
56
- if (b.type === 'ImportDeclaration' && b.source.value.endsWith('.gts')) {
57
- const value = b.source.value.replace(/\.gts$/, '.mts');
58
- const strWrapper = jsCode[b.source.start];
59
- jsCode = replaceRange(
60
- jsCode,
61
- b.source.start,
62
- b.source.end,
63
- strWrapper + value + strWrapper
64
- );
66
+ for (const b of sourceFile.statements) {
67
+ if (b.kind === ts.SyntaxKind.ImportDeclaration && b.moduleSpecifier.text.endsWith('.gts')) {
68
+ const value = b.moduleSpecifier.text.replace(/\.gts$/, '.mts');
69
+ jsCode = replaceRange(jsCode, b.moduleSpecifier.pos + 2, b.moduleSpecifier.end - 1, value);
65
70
  }
66
71
  }
67
72
  if (length !== jsCode.length) {