Merge pull request #1134 from Microsoft/constLet
Fixes the const and let nav bar, quickInfo, Completion List
This commit is contained in:
commit
dc3bd6a932
|
@ -18,7 +18,7 @@ module ts {
|
|||
return ModuleInstanceState.NonInstantiated;
|
||||
}
|
||||
// 2. const enum declarations don't make module instantiated
|
||||
else if (node.kind === SyntaxKind.EnumDeclaration && isConstEnumDeclaration(<EnumDeclaration>node)) {
|
||||
else if (isConstEnumDeclaration(node)) {
|
||||
return ModuleInstanceState.ConstEnumOnly;
|
||||
}
|
||||
// 3. non - exported import declarations
|
||||
|
@ -439,7 +439,7 @@ module ts {
|
|||
bindDeclaration(<Declaration>node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
if (isConstEnumDeclaration(<EnumDeclaration>node)) {
|
||||
if (isConst(node)) {
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes, /*isBlockScopeContainer*/ false);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -8007,7 +8007,7 @@ module ts {
|
|||
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
|
||||
var autoValue = 0;
|
||||
var ambient = isInAmbientContext(node);
|
||||
var enumIsConst = isConstEnumDeclaration(node);
|
||||
var enumIsConst = isConst(node);
|
||||
|
||||
forEach(node.members, member => {
|
||||
// TODO(jfreeman): Check that it is not a computed name
|
||||
|
@ -8178,10 +8178,10 @@ module ts {
|
|||
var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
|
||||
if (node === firstDeclaration) {
|
||||
if (enumSymbol.declarations.length > 1) {
|
||||
var enumIsConst = isConstEnumDeclaration(node);
|
||||
var enumIsConst = isConst(node);
|
||||
// check that const is placed\omitted on all enum declarations
|
||||
forEach(enumSymbol.declarations, decl => {
|
||||
if (isConstEnumDeclaration(<EnumDeclaration>decl) !== enumIsConst) {
|
||||
if (isConstEnumDeclaration(decl) !== enumIsConst) {
|
||||
error(decl.name, Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -720,7 +720,7 @@ module ts {
|
|||
if (resolver.isDeclarationVisible(node)) {
|
||||
emitJsDocComments(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
if (isConstEnumDeclaration(node)) {
|
||||
if (isConst(node)) {
|
||||
write("const ")
|
||||
}
|
||||
write("enum ");
|
||||
|
@ -997,10 +997,10 @@ module ts {
|
|||
if (hasDeclarationWithEmit) {
|
||||
emitJsDocComments(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
if (isLet(node)) {
|
||||
write("let ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
else if (isConst(node)) {
|
||||
write("const ");
|
||||
}
|
||||
else {
|
||||
|
@ -2465,10 +2465,10 @@ module ts {
|
|||
write(" ");
|
||||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
if (node.declarations) {
|
||||
if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Let) {
|
||||
if (node.declarations[0] && isLet(node.declarations[0])) {
|
||||
emitToken(SyntaxKind.LetKeyword, endPos);
|
||||
}
|
||||
else if (node.declarations[0] && node.declarations[0].flags & NodeFlags.Const) {
|
||||
else if (node.declarations[0] && isConst(node.declarations[0])) {
|
||||
emitToken(SyntaxKind.ConstKeyword, endPos);
|
||||
}
|
||||
else {
|
||||
|
@ -2495,7 +2495,7 @@ module ts {
|
|||
if (node.declarations) {
|
||||
if (node.declarations.length >= 1) {
|
||||
var decl = node.declarations[0];
|
||||
if (decl.flags & NodeFlags.Let) {
|
||||
if (isLet(decl)) {
|
||||
emitToken(SyntaxKind.LetKeyword, endPos);
|
||||
}
|
||||
else {
|
||||
|
@ -2642,10 +2642,10 @@ module ts {
|
|||
function emitVariableStatement(node: VariableStatement) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
if (isLet(node)) {
|
||||
write("let ");
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
else if (isConst(node)) {
|
||||
write("const ");
|
||||
}
|
||||
else {
|
||||
|
@ -3098,7 +3098,7 @@ module ts {
|
|||
|
||||
function emitEnumDeclaration(node: EnumDeclaration) {
|
||||
// const enums are completely erased during compilation.
|
||||
var isConstEnum = isConstEnumDeclaration(node);
|
||||
var isConstEnum = isConst(node);
|
||||
if (isConstEnum && !compilerOptions.preserveConstEnums) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -125,8 +125,16 @@ module ts {
|
|||
return (file.flags & NodeFlags.DeclarationFile) !== 0;
|
||||
}
|
||||
|
||||
export function isConstEnumDeclaration(node: EnumDeclaration): boolean {
|
||||
return (node.flags & NodeFlags.Const) !== 0;
|
||||
export function isConstEnumDeclaration(node: Declaration): boolean {
|
||||
return node.kind === SyntaxKind.EnumDeclaration && isConst(node);
|
||||
}
|
||||
|
||||
export function isConst(node: Declaration): boolean {
|
||||
return !!(node.flags & NodeFlags.Const);
|
||||
}
|
||||
|
||||
export function isLet(node: Declaration): boolean {
|
||||
return !!(node.flags & NodeFlags.Let);
|
||||
}
|
||||
|
||||
export function isPrologueDirective(node: Node): boolean {
|
||||
|
@ -4548,7 +4556,7 @@ module ts {
|
|||
var equalsPos = node.type ? skipTrivia(sourceText, node.type.end) : skipTrivia(sourceText, node.name.end);
|
||||
return grammarErrorAtPos(equalsPos, "=".length, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
}
|
||||
if (!inAmbientContext && !node.initializer && node.flags & NodeFlags.Const) {
|
||||
if (!inAmbientContext && !node.initializer && isConst(node)) {
|
||||
return grammarErrorOnNode(node, Diagnostics.const_declarations_must_be_initialized);
|
||||
}
|
||||
if (node.flags & NodeFlags.ParsedInStrictMode && isEvalOrArgumentsIdentifier(node.name)) {
|
||||
|
@ -4570,10 +4578,10 @@ module ts {
|
|||
|
||||
var decl = declarations[0];
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (decl.flags & NodeFlags.Let) {
|
||||
if (isLet(decl)) {
|
||||
return grammarErrorOnFirstToken(decl, Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
else if (decl.flags & NodeFlags.Const) {
|
||||
else if (isConst(decl)) {
|
||||
return grammarErrorOnFirstToken(decl, Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
}
|
||||
|
@ -4587,10 +4595,10 @@ module ts {
|
|||
|
||||
function checkForDisallowedLetOrConstStatement(node: VariableStatement) {
|
||||
if (!allowLetAndConstDeclarations(node.parent)) {
|
||||
if (node.flags & NodeFlags.Let) {
|
||||
if (isLet(node)) {
|
||||
return grammarErrorOnNode(node, Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
|
||||
}
|
||||
else if (node.flags & NodeFlags.Const) {
|
||||
else if (isConst(node)) {
|
||||
return grammarErrorOnNode(node, Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,8 +234,11 @@ module ts.NavigationBar {
|
|||
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (node.flags & NodeFlags.Const) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constantElement);
|
||||
if (isConst(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constElement);
|
||||
}
|
||||
else if (isLet(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.letElement);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
|
||||
|
|
|
@ -1242,7 +1242,9 @@ module ts {
|
|||
|
||||
static alias = "alias";
|
||||
|
||||
static constantElement = "constant";
|
||||
static constElement = "const";
|
||||
|
||||
static letElement = "let";
|
||||
}
|
||||
|
||||
export class ScriptElementKindModifier {
|
||||
|
@ -2770,8 +2772,11 @@ module ts {
|
|||
if (isFirstDeclarationOfSymbolParameter(symbol)) {
|
||||
return ScriptElementKind.parameterElement;
|
||||
}
|
||||
else if(symbol.valueDeclaration && symbol.valueDeclaration.flags & NodeFlags.Const) {
|
||||
return ScriptElementKind.constantElement;
|
||||
else if (symbol.valueDeclaration && isConst(symbol.valueDeclaration)) {
|
||||
return ScriptElementKind.constElement;
|
||||
}
|
||||
else if (forEach(symbol.declarations, declaration => isLet(declaration))) {
|
||||
return ScriptElementKind.letElement;
|
||||
}
|
||||
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
|
||||
}
|
||||
|
@ -2828,7 +2833,11 @@ module ts {
|
|||
case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement;
|
||||
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
case SyntaxKind.VariableDeclaration: return node.flags & NodeFlags.Const ? ScriptElementKind.constantElement: ScriptElementKind.variableElement;
|
||||
case SyntaxKind.VariableDeclaration: return isConst(node)
|
||||
? ScriptElementKind.constElement
|
||||
: node.flags & NodeFlags.Let
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement;
|
||||
case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement;
|
||||
case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement;
|
||||
|
@ -2927,7 +2936,7 @@ module ts {
|
|||
switch (symbolKind) {
|
||||
case ScriptElementKind.memberVariableElement:
|
||||
case ScriptElementKind.variableElement:
|
||||
case ScriptElementKind.constantElement:
|
||||
case ScriptElementKind.constElement:
|
||||
case ScriptElementKind.parameterElement:
|
||||
case ScriptElementKind.localVariableElement:
|
||||
// If it is call or construct signature of lambda's write type name
|
||||
|
@ -3003,6 +3012,10 @@ module ts {
|
|||
}
|
||||
if (symbolFlags & SymbolFlags.Enum) {
|
||||
addNewLineIfDisplayPartsExist();
|
||||
if (forEach(symbol.declarations, declaration => isConstEnumDeclaration(declaration))) {
|
||||
displayParts.push(keywordPart(SyntaxKind.ConstKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
displayParts.push(keywordPart(SyntaxKind.EnumKeyword));
|
||||
displayParts.push(spacePart());
|
||||
addFullSymbolName(symbol);
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
/////**/
|
||||
|
||||
goTo.marker();
|
||||
verify.completionListContains("c", /*text*/ undefined, /*documentation*/ undefined, "constant");
|
||||
verify.completionListContains("c", "(const) c: string", /*documentation*/ undefined, "const");
|
15
tests/cases/fourslash/constEnumQuickInfoAndCompletionList.ts
Normal file
15
tests/cases/fourslash/constEnumQuickInfoAndCompletionList.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const enum /*1*/e {
|
||||
//// a,
|
||||
//// b,
|
||||
//// c
|
||||
////}
|
||||
/////*2*/e.a;
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs("const enum e");
|
||||
|
||||
goTo.marker('2');
|
||||
verify.completionListContains("e", "const enum e");
|
||||
verify.quickInfoIs("const enum e");
|
37
tests/cases/fourslash/constQuickInfoAndCompletionList.ts
Normal file
37
tests/cases/fourslash/constQuickInfoAndCompletionList.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const /*1*/a = 10;
|
||||
////var x = /*2*/a;
|
||||
/////*3*/
|
||||
////function foo() {
|
||||
//// const /*4*/b = 20;
|
||||
//// var y = /*5*/b;
|
||||
//// var z = /*6*/a;
|
||||
//// /*7*/
|
||||
////}
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs("(const) a: number");
|
||||
|
||||
goTo.marker('2');
|
||||
verify.completionListContains("a", "(const) a: number");
|
||||
verify.quickInfoIs("(const) a: number");
|
||||
|
||||
goTo.marker('3');
|
||||
verify.completionListContains("a", "(const) a: number");
|
||||
|
||||
goTo.marker('4');
|
||||
verify.quickInfoIs("(const) b: number");
|
||||
|
||||
goTo.marker('5');
|
||||
verify.completionListContains("a", "(const) a: number");
|
||||
verify.completionListContains("b", "(const) b: number");
|
||||
verify.quickInfoIs("(const) b: number");
|
||||
|
||||
goTo.marker('6');
|
||||
verify.completionListContains("a", "(const) a: number");
|
||||
verify.completionListContains("b", "(const) b: number");
|
||||
verify.quickInfoIs("(const) a: number");
|
||||
|
||||
goTo.marker('7');
|
||||
verify.completionListContains("a", "(const) a: number");
|
||||
verify.completionListContains("b", "(const) b: number");
|
28
tests/cases/fourslash/letQuickInfoAndCompletionList.ts
Normal file
28
tests/cases/fourslash/letQuickInfoAndCompletionList.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////let /*1*/a = 10;
|
||||
/////*2*/a = 30;
|
||||
////function foo() {
|
||||
//// let /*3*/b = 20;
|
||||
//// /*4*/b = /*5*/a;
|
||||
////}
|
||||
|
||||
goTo.marker('1');
|
||||
verify.quickInfoIs("(let) a: number");
|
||||
|
||||
goTo.marker('2');
|
||||
verify.completionListContains("a", "(let) a: number");
|
||||
verify.quickInfoIs("(let) a: number");
|
||||
|
||||
goTo.marker('3');
|
||||
verify.quickInfoIs("(let) b: number");
|
||||
|
||||
goTo.marker('4');
|
||||
verify.completionListContains("a", "(let) a: number");
|
||||
verify.completionListContains("b", "(let) b: number");
|
||||
verify.quickInfoIs("(let) b: number");
|
||||
|
||||
goTo.marker('5');
|
||||
verify.completionListContains("a", "(let) a: number");
|
||||
verify.completionListContains("b", "(let) b: number");
|
||||
verify.quickInfoIs("(let) a: number");
|
|
@ -1,6 +1,6 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// {| "itemName": "c", "kind": "constant", "parentName": "" |}const c = 0;
|
||||
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.getScriptLexicalStructureListContains(
|
||||
|
|
13
tests/cases/fourslash/navbar_let.ts
Normal file
13
tests/cases/fourslash/navbar_let.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// {| "itemName": "c", "kind": "let", "parentName": "" |}let c = 0;
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.getScriptLexicalStructureListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.fileName,
|
||||
marker.data.parentName,
|
||||
marker.data.isAdditionalRange,
|
||||
marker.position);
|
||||
});
|
16
tests/cases/fourslash/navigateItemsConst.ts
Normal file
16
tests/cases/fourslash/navigateItemsConst.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////{| "itemName": "c", "kind": "const", "parentName": "" |}const c = 10;
|
||||
////function foo() {
|
||||
//// {| "itemName": "d", "kind": "const", "parentName": "foo" |}const d = 10;
|
||||
////}
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.navigationItemsListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.data.itemName,
|
||||
"exact",
|
||||
marker.fileName,
|
||||
marker.data.parentName);
|
||||
});
|
16
tests/cases/fourslash/navigateItemsLet.ts
Normal file
16
tests/cases/fourslash/navigateItemsLet.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////{| "itemName": "c", "kind": "let", "parentName": "" |}let c = 10;
|
||||
////function foo() {
|
||||
//// {| "itemName": "d", "kind": "let", "parentName": "foo" |}let d = 10;
|
||||
////}
|
||||
|
||||
test.markers().forEach(marker => {
|
||||
verify.navigationItemsListContains(
|
||||
marker.data.itemName,
|
||||
marker.data.kind,
|
||||
marker.data.itemName,
|
||||
"exact",
|
||||
marker.fileName,
|
||||
marker.data.parentName);
|
||||
});
|
|
@ -3,4 +3,4 @@
|
|||
////const /**/c = 0 ;
|
||||
|
||||
goTo.marker();
|
||||
verify.quickInfoIs("(constant) c: number");
|
||||
verify.quickInfoIs("(const) c: number");
|
Loading…
Reference in a new issue