-
Notifications
You must be signed in to change notification settings - Fork 13k
Wire getReferences to use the new compiler #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8151f5e
5e9b2b5
32a5984
6a92b21
f45ab42
f84d2af
901e8a8
69c653d
bfd1334
fa1033a
55d0021
d419982
922d6d6
7f53783
f812297
3251b7e
2d4cec4
55512fa
978c2ef
74518a9
e0ffc47
bbeeb8d
6965a06
dbf9e47
fefe2fb
c741e26
8fcc8b2
6953794
892baf0
5c1b245
aef859f
144eb8d
f948f5d
e851e4b
3c97210
5d15cd2
558be4e
1f77198
8ab4df0
88f37e5
3825c9b
232e513
0f9c1ad
50d0cdc
ea613fd
04456a2
0ce39a3
5b7da99
fd93a3b
813f28d
41d8d6c
dc0560a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,46 @@ module ts { | |
return false; | ||
} | ||
|
||
export function isDeclaration(node: Node): boolean { | ||
switch (node.kind) { | ||
case SyntaxKind.TypeParameter: | ||
case SyntaxKind.Parameter: | ||
case SyntaxKind.VariableDeclaration: | ||
case SyntaxKind.Property: | ||
case SyntaxKind.PropertyAssignment: | ||
case SyntaxKind.EnumMember: | ||
case SyntaxKind.Method: | ||
case SyntaxKind.FunctionDeclaration: | ||
case SyntaxKind.GetAccessor: | ||
case SyntaxKind.SetAccessor: | ||
case SyntaxKind.ClassDeclaration: | ||
case SyntaxKind.InterfaceDeclaration: | ||
case SyntaxKind.EnumDeclaration: | ||
case SyntaxKind.ModuleDeclaration: | ||
case SyntaxKind.ImportDeclaration: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// True if the given identifier, string literal, or number literal is the name of a declaration node | ||
export function isDeclarationOrFunctionExpressionOrCatchVariableName(name: Node): boolean { | ||
if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) { | ||
return false; | ||
} | ||
|
||
var parent = name.parent; | ||
if (isDeclaration(parent) || parent.kind === SyntaxKind.FunctionExpression) { | ||
return (<Declaration>parent).name === name; | ||
} | ||
|
||
if (parent.kind === SyntaxKind.CatchBlock) { | ||
return (<CatchBlock>parent).variable === name; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, put these back in checker, since they use parent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think about moving these to a module, which would contain all syntax utilities that assume parent pointers have been set up |
||
enum ParsingContext { | ||
SourceElements, // Elements in source file | ||
ModuleElements, // Elements in module declaration | ||
|
@@ -444,6 +484,22 @@ module ts { | |
nodeIsNestedInLabel(label: Identifier, requireIterationStatement: boolean, stopAtFunctionBoundary: boolean): ControlBlockContext; | ||
} | ||
|
||
export function isKeyword(token: SyntaxKind): boolean { | ||
return SyntaxKind.FirstKeyword <= token && token <= SyntaxKind.LastKeyword; | ||
} | ||
|
||
export function isModifier(token: SyntaxKind): boolean { | ||
switch (token) { | ||
case SyntaxKind.PublicKeyword: | ||
case SyntaxKind.PrivateKeyword: | ||
case SyntaxKind.StaticKeyword: | ||
case SyntaxKind.ExportKeyword: | ||
case SyntaxKind.DeclareKeyword: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export function createSourceFile(filename: string, sourceText: string, languageVersion: ScriptTarget, version: string, isOpen: boolean = false): SourceFile { | ||
var file: SourceFile; | ||
var scanner: Scanner; | ||
|
@@ -775,6 +831,10 @@ module ts { | |
return createNode(SyntaxKind.Missing); | ||
} | ||
|
||
function internIdentifier(text: string): string { | ||
return hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); | ||
} | ||
|
||
// An identifier that starts with two underscores has an extra underscore character prepended to it to avoid issues | ||
// with magic property names like '__proto__'. The 'identifiers' object is used to share a single string instance for | ||
// each identifier in order to reduce memory consumption. | ||
|
@@ -783,7 +843,7 @@ module ts { | |
if (isIdentifier) { | ||
var node = <Identifier>createNode(SyntaxKind.Identifier); | ||
var text = escapeIdentifier(scanner.getTokenValue()); | ||
node.text = hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); | ||
node.text = internIdentifier(text); | ||
nextToken(); | ||
return finishNode(node); | ||
} | ||
|
@@ -805,28 +865,11 @@ module ts { | |
|
||
function parsePropertyName(): Identifier { | ||
if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) { | ||
return <LiteralExpression>parsePrimaryExpression(); | ||
return parseLiteralNode(/*internName:*/ true); | ||
} | ||
return parseIdentifierName(); | ||
} | ||
|
||
|
||
function isKeyword(token: SyntaxKind): boolean { | ||
return SyntaxKind.FirstKeyword <= token && token <= SyntaxKind.LastKeyword; | ||
} | ||
|
||
function isModifier(token: SyntaxKind): boolean { | ||
switch (token) { | ||
case SyntaxKind.PublicKeyword: | ||
case SyntaxKind.PrivateKeyword: | ||
case SyntaxKind.StaticKeyword: | ||
case SyntaxKind.ExportKeyword: | ||
case SyntaxKind.DeclareKeyword: | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function parseContextualModifier(t: SyntaxKind): boolean { | ||
return token === t && tryParse(() => { | ||
nextToken(); | ||
|
@@ -1086,9 +1129,11 @@ module ts { | |
return finishNode(node); | ||
} | ||
|
||
function parseLiteralNode(): LiteralExpression { | ||
function parseLiteralNode(internName?:boolean): LiteralExpression { | ||
var node = <LiteralExpression>createNode(token); | ||
node.text = scanner.getTokenValue(); | ||
var text = scanner.getTokenValue(); | ||
node.text = internName ? internIdentifier(text) : text; | ||
|
||
var tokenPos = scanner.getTokenPos(); | ||
nextToken(); | ||
finishNode(node); | ||
|
@@ -1115,7 +1160,7 @@ module ts { | |
} | ||
|
||
function parseStringLiteral(): LiteralExpression { | ||
if (token === SyntaxKind.StringLiteral) return parseLiteralNode(); | ||
if (token === SyntaxKind.StringLiteral) return parseLiteralNode(/*internName:*/ true); | ||
error(Diagnostics.String_literal_expected); | ||
return <LiteralExpression>createMissingNode(); | ||
} | ||
|
@@ -2019,6 +2064,10 @@ module ts { | |
} | ||
else { | ||
indexedAccess.index = parseExpression(); | ||
if (indexedAccess.index.kind === SyntaxKind.StringLiteral || indexedAccess.index.kind === SyntaxKind.NumericLiteral) { | ||
var literal = <LiteralExpression>indexedAccess.index; | ||
literal.text = internIdentifier(literal.text); | ||
} | ||
parseExpected(SyntaxKind.CloseBracketToken); | ||
} | ||
|
||
|
@@ -3569,6 +3618,7 @@ module ts { | |
file.version = version; | ||
file.isOpen = isOpen; | ||
file.languageVersion = languageVersion; | ||
file.identifiers = identifiers; | ||
return file; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,6 +441,18 @@ module ts { | |
return getCommentRanges(text, pos, /*trailing*/ true); | ||
} | ||
|
||
export function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean { | ||
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z || | ||
ch === CharacterCodes.$ || ch === CharacterCodes._ || | ||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierStart(ch, languageVersion); | ||
} | ||
|
||
export function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean { | ||
return ch >= CharacterCodes.A && ch <= CharacterCodes.Z || ch >= CharacterCodes.a && ch <= CharacterCodes.z || | ||
ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ || | ||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are already here! Make sure they are not duplicated |
||
export function createScanner(languageVersion: ScriptTarget, text?: string, onError?: ErrorCallback, onComment?: CommentCallback): Scanner { | ||
var pos: number; // Current position (end position of text of current token) | ||
var len: number; // Length of text | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -537,6 +537,7 @@ module ts { | |
isOpen: boolean; | ||
version: string; | ||
languageVersion: ScriptTarget; | ||
identifiers: Map<string>; | ||
} | ||
|
||
export interface Program { | ||
|
@@ -616,6 +617,8 @@ module ts { | |
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string; | ||
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string; | ||
getAugmentedPropertiesOfApparentType(type: Type): Symbol[]; | ||
getRootSymbol(symbol: Symbol): Symbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment what this does |
||
getContextualType(node: Node): Type; | ||
} | ||
|
||
export interface TextWriter { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth commenting why it is transient