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

Offer semantic services alongside AST #24

Merged
merged 33 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3c10816
feat: use cwd to find tsconfig and build program
Sep 26, 2018
1697aed
fix: use text read by eslint
Sep 28, 2018
adc6724
fix: ensure ast maps are unique to each parse result
Oct 3, 2018
459db21
fix: handle files not included in ts project more robustly
Oct 4, 2018
7f1ba19
chore: fix indentation
Oct 4, 2018
b4377a9
fix: remove duplicated code from merge
Oct 4, 2018
d2d6a31
fix: re-add missing argument
Oct 4, 2018
c3cc2da
fix: take tsconfig paths from eslintrc rather than finding one
Oct 8, 2018
4821647
perf: reuse existing programs and supply outdated to create new programs
Oct 9, 2018
9dbd1fb
fix: appropriately handle malformed tsconfigs
Oct 9, 2018
4f9608a
test: add test for semantic info in isolated file
Oct 11, 2018
d2d12b7
test: add bad project input tests
Oct 12, 2018
460953d
test: add test validating cross-file type resolution
Oct 12, 2018
2315459
chore: add comment to test
Oct 12, 2018
ade71f2
chore: limit badtsconfig for readability
Oct 12, 2018
b3c407f
chore: update test header
Oct 12, 2018
47c9b1c
perf: use TS watch API to track changes to programs
Oct 17, 2018
fb5470c
fix: ensure changes to the linted file are detected
Oct 18, 2018
f27a444
fix: improve project option validation
Oct 18, 2018
234fe43
chore: remove unnecessary comments from tsconfig in tests
Oct 18, 2018
01a312b
fix: report config file errors whenever the program updates
Oct 22, 2018
8e60d5f
fix: add sourcefile to more operations
Oct 29, 2018
8a46d08
refactor: only pass projects to project option handling
Oct 29, 2018
285cbd1
refactor: break up program creation for readability
Oct 29, 2018
7e54657
refactor: add comment and use util function
Oct 29, 2018
d4435ea
fix: don't try to convert symbols
Nov 5, 2018
7fd22df
chore: merge branch 'master' into semanticServices
Nov 5, 2018
89787c4
test: update semanticInfo baseline to be path-agnostic
Nov 5, 2018
d23645a
Merge branch 'master' into semanticServices
JamesHenry Nov 8, 2018
5d6708a
refactor: rename tsconfig root directory option and respond to cr
Nov 9, 2018
3982abf
fix: undo resolveJsonModule to avoid changing dist structure
Nov 9, 2018
2f8a07e
Merge branch 'master' into semanticServices
JamesHenry Nov 11, 2018
792ee88
refactor: move generating services to separate top-level function
Nov 14, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/jest": "^23.3.9",
"@types/lodash.isplainobject": "^4.0.4",
"@types/lodash.unescape": "^4.0.4",
"@types/node": "^10.12.2",
"@types/semver": "^5.5.0",
"@types/shelljs": "^0.8.0",
"babel-code-frame": "6.26.0",
Expand Down
24 changes: 18 additions & 6 deletions src/ast-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/
import { convert } from './convert';
import convert, { getASTMaps, resetASTMaps } from './convert';
import { convertComments } from './convert-comments';
import nodeUtils from './node-utils';
import ts from 'typescript';
import { Extra } from './temp-types-based-on-js-source';

/**
Expand All @@ -23,13 +24,17 @@ function convertError(error: any) {
);
}

export default (ast: any, extra: Extra) => {
export default (
ast: ts.SourceFile,
extra: Extra,
shouldProvideParserServices: boolean
) => {
/**
* The TypeScript compiler produced fundamental parse errors when parsing the
* source.
*/
if (ast.parseDiagnostics.length) {
throw convertError(ast.parseDiagnostics[0]);
if ((ast as any).parseDiagnostics.length) {
throw convertError((ast as any).parseDiagnostics[0]);
}

/**
Expand All @@ -41,7 +46,8 @@ export default (ast: any, extra: Extra) => {
ast,
additionalOptions: {
errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
useJSXTextNode: extra.useJSXTextNode || false
useJSXTextNode: extra.useJSXTextNode || false,
shouldProvideParserServices
}
});

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

return estree;
let astMaps = undefined;
if (shouldProvideParserServices) {
astMaps = getASTMaps();
resetASTMaps();
}

return { estree, astMaps };
};
Loading