Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit 8787f16

Browse files
uniqueiniquityJamesHenry
authored andcommitted
feat: offer semantic services alongside AST (#24)
1 parent 383616e commit 8787f16

16 files changed

+1849
-121
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/jest": "^23.3.9",
2626
"@types/lodash.isplainobject": "^4.0.4",
2727
"@types/lodash.unescape": "^4.0.4",
28+
"@types/node": "^10.12.2",
2829
"@types/semver": "^5.5.0",
2930
"@types/shelljs": "^0.8.0",
3031
"babel-code-frame": "6.26.0",

src/ast-converter.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
* @copyright jQuery Foundation and other contributors, https://jquery.org/
66
* MIT License
77
*/
8-
import { convert } from './convert';
8+
import convert, { getASTMaps, resetASTMaps } from './convert';
99
import { convertComments } from './convert-comments';
1010
import nodeUtils from './node-utils';
11+
import ts from 'typescript';
1112
import { Extra } from './temp-types-based-on-js-source';
1213

1314
/**
@@ -23,13 +24,17 @@ function convertError(error: any) {
2324
);
2425
}
2526

26-
export default (ast: any, extra: Extra) => {
27+
export default (
28+
ast: ts.SourceFile,
29+
extra: Extra,
30+
shouldProvideParserServices: boolean
31+
) => {
2732
/**
2833
* The TypeScript compiler produced fundamental parse errors when parsing the
2934
* source.
3035
*/
31-
if (ast.parseDiagnostics.length) {
32-
throw convertError(ast.parseDiagnostics[0]);
36+
if ((ast as any).parseDiagnostics.length) {
37+
throw convertError((ast as any).parseDiagnostics[0]);
3338
}
3439

3540
/**
@@ -41,7 +46,8 @@ export default (ast: any, extra: Extra) => {
4146
ast,
4247
additionalOptions: {
4348
errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
44-
useJSXTextNode: extra.useJSXTextNode || false
49+
useJSXTextNode: extra.useJSXTextNode || false,
50+
shouldProvideParserServices
4551
}
4652
});
4753

@@ -59,5 +65,11 @@ export default (ast: any, extra: Extra) => {
5965
estree.comments = convertComments(ast, extra.code);
6066
}
6167

62-
return estree;
68+
let astMaps = undefined;
69+
if (shouldProvideParserServices) {
70+
astMaps = getASTMaps();
71+
resetASTMaps();
72+
}
73+
74+
return { estree, astMaps };
6375
};

0 commit comments

Comments
 (0)