ember-eslint-parser 0.3.6 → 0.3.8

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/README.md CHANGED
@@ -28,6 +28,9 @@ It's recommended to only use _overrides_ when defining your eslint config, so us
28
28
  },
29
29
  ```
30
30
 
31
+ if we detect a typescript parser, it will also be used for all files, otherwise babel parser will be used.
32
+ If we cannot find a typescript parser when linting gts we throw an error.
33
+
31
34
  ## Support
32
35
 
33
36
  eslint-plugin-ember is the primary consumer of this parser library, so SemVer _may_ not be respected for other consumers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-eslint-parser",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -28,6 +28,11 @@ module.exports = {
28
28
  jsCode = info.output;
29
29
 
30
30
  const isTypescript = options.filePath.endsWith('.gts') || options.filePath.endsWith('.ts');
31
+ let useTypescript = true;
32
+
33
+ if (options.useBabel || !typescriptParser) {
34
+ useTypescript = false;
35
+ }
31
36
 
32
37
  let result = null;
33
38
  const filePath = options.filePath;
@@ -40,13 +45,19 @@ module.exports = {
40
45
  }
41
46
 
42
47
  try {
43
- result = isTypescript
44
- ? typescriptParser.parseForESLint(jsCode, { ...options, ranges: true, filePath })
45
- : babelParser.parseForESLint(jsCode, {
46
- ...options,
47
- requireConfigFile: false,
48
- ranges: true,
49
- });
48
+ result =
49
+ isTypescript || useTypescript
50
+ ? typescriptParser.parseForESLint(jsCode, {
51
+ ...options,
52
+ ranges: true,
53
+ extraFileExtensions: ['.gts', '.gjs'],
54
+ filePath,
55
+ })
56
+ : babelParser.parseForESLint(jsCode, {
57
+ ...options,
58
+ requireConfigFile: false,
59
+ ranges: true,
60
+ });
50
61
  if (!info.templateInfos?.length) {
51
62
  return result;
52
63
  }
@@ -54,7 +65,7 @@ module.exports = {
54
65
  preprocessedResult.code = code;
55
66
  const { templateVisitorKeys } = preprocessedResult;
56
67
  const visitorKeys = { ...result.visitorKeys, ...templateVisitorKeys };
57
- result.isTypescript = isTypescript;
68
+ result.isTypescript = isTypescript || useTypescript;
58
69
  convertAst(result, preprocessedResult, visitorKeys);
59
70
  if (result.services?.program) {
60
71
  syncMtsGtsSourceFiles(result.services?.program);
@@ -23,15 +23,19 @@ try {
23
23
  ];
24
24
  },
25
25
  fileExists(fileName) {
26
- return fs.existsSync(fileName.replace(/\.mts$/, '.gts')) || fs.existsSync(fileName);
26
+ return fs.existsSync(fileName.replace(/\.m?ts$/, '.gts')) || fs.existsSync(fileName);
27
27
  },
28
28
  readFile(fname) {
29
29
  let fileName = fname;
30
30
  let content = '';
31
+ if (fileName.endsWith('tsconfig.tsbuildinfo')) {
32
+ return content;
33
+ }
34
+
31
35
  try {
32
36
  content = fs.readFileSync(fileName).toString();
33
37
  } catch {
34
- fileName = fileName.replace(/\.mts$/, '.gts');
38
+ fileName = fileName.replace(/\.m?ts$/, '.gts');
35
39
  content = fs.readFileSync(fileName).toString();
36
40
  }
37
41
  if (fileName.endsWith('.gts')) {
@@ -83,8 +87,8 @@ try {
83
87
  const sourceFiles = program.getSourceFiles();
84
88
  for (const sourceFile of sourceFiles) {
85
89
  // check for deleted gts files, need to remove mts as well
86
- if (sourceFile.path.endsWith('.mts') && sourceFile.isVirtualGts) {
87
- const gtsFile = program.getSourceFile(sourceFile.path.replace(/\.mts$/, '.gts'));
90
+ if (sourceFile.path.match(/\.m?ts$/) && sourceFile.isVirtualGts) {
91
+ const gtsFile = program.getSourceFile(sourceFile.path.replace(/\.m?ts$/, '.gts'));
88
92
  if (!gtsFile) {
89
93
  sourceFile.version = null;
90
94
  }
@@ -93,7 +97,10 @@ try {
93
97
  /**
94
98
  * @type {ts.SourceFile}
95
99
  */
96
- const mtsSourceFile = program.getSourceFile(sourceFile.path.replace(/\.gts$/, '.mts'));
100
+ let mtsSourceFile = program.getSourceFile(sourceFile.path.replace(/\.gts$/, '.mts'));
101
+ if (!mtsSourceFile) {
102
+ mtsSourceFile = program.getSourceFile(sourceFile.path.replace(/\.gts$/, '.ts'));
103
+ }
97
104
  if (mtsSourceFile) {
98
105
  const keep = {
99
106
  fileName: mtsSourceFile.fileName,