Skip to content

Commit f720718

Browse files
committed
Using new parser code by using SourceFileObject.createSourceFileObject.
Could simply use `ts.createSourceFileObject`, but in that case `getSyntaxTree()` won't work since it relies on existing of `scriptSnapshot` property. Could also simply add this property, but decided to go with corresponding ready-to-use factory for better maintainability.
1 parent dcdc9bb commit f720718

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/main/mode.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class FormattingOptions {
3232
import logger = require('../commons/logger');
3333
import Formatting = TypeScript.Services.Formatting;
3434

35+
// exposing SourceFileObject.createSourceFileObject
36+
var createSourceFileObject: (filename: string, scriptSnapshot: TypeScript.IScriptSnapshot, languageVersion: ts.ScriptTarget) => ts.SourceFile =
37+
(<any>ts.getNodeConstructor(ts.SyntaxKind.SourceFile).prototype.constructor).createSourceFileObject;
38+
3539
class Token {
3640
string: string;
3741
classification: ts.TokenClass;
@@ -139,14 +143,17 @@ class TypeScriptMode implements CodeMirror.CodeMirrorMode<LineDescriptor> {
139143

140144
}
141145

142-
private getSyntaxTree(text: string) {
143-
return TypeScript.Parser.parse(
144-
'script',
145-
TypeScript.SimpleText.fromString(text),
146-
ts.ScriptTarget.ES5,
147-
false
146+
private createSourceFile(text: string) {
147+
return createSourceFileObject(
148+
'script',
149+
TypeScript.ScriptSnapshot.fromString(text),
150+
ts.ScriptTarget.ES5
148151
);
149152
}
153+
154+
private getSyntaxTree(text: string) {
155+
return this.createSourceFile(text).getSyntaxTree();
156+
}
150157
}
151158

152159

0 commit comments

Comments
 (0)