Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ module ts {
}
result = undefined;
}
else if (location.kind === SyntaxKind.SourceFile) {
result = getSymbol(getSymbolOfNode(location).exports, "default", meaning & SymbolFlags.ModuleMember);
let localSymbol = getLocalSymbolForExportDefault(result);
if (result && (result.flags & meaning) && localSymbol && localSymbol.name === name) {
break loop;
}
result = undefined;
}
break;
case SyntaxKind.EnumDeclaration:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.EnumMember)) {
Expand Down
18 changes: 11 additions & 7 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module ts {

return node.pos === node.end && node.kind !== SyntaxKind.EndOfFileToken;
}

export function nodeIsPresent(node: Node) {
return !nodeIsMissing(node);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ module ts {
errorNode = (<Declaration>node).name;
break;
}

if (errorNode === undefined) {
// If we don't have a better node, then just set the error on the first token of
// construct.
Expand Down Expand Up @@ -642,7 +642,7 @@ module ts {

return false;
}

export function childIsDecorated(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.ClassDeclaration:
Expand Down Expand Up @@ -754,7 +754,7 @@ module ts {
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
let moduleState = getModuleInstanceState(node)
return moduleState === ModuleInstanceState.Instantiated ||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
}

export function isExternalModuleImportEqualsDeclaration(node: Node) {
Expand Down Expand Up @@ -1170,7 +1170,7 @@ module ts {
export function createTextSpanFromBounds(start: number, end: number) {
return createTextSpan(start, end - start);
}

export function textChangeRangeNewSpan(range: TextChangeRange) {
return createTextSpan(range.span.start, range.newLength);
}
Expand Down Expand Up @@ -1444,13 +1444,13 @@ module ts {
return escapedCharsMap[c] || get16BitUnicodeEscapeSequence(c.charCodeAt(0));
}
}

function get16BitUnicodeEscapeSequence(charCode: number): string {
let hexCharCode = charCode.toString(16).toUpperCase();
let paddedHexCode = ("0000" + hexCharCode).slice(-4);
return "\\u" + paddedHexCode;
}

let nonAsciiCharacters = /[^\u0000-\u007F]/g;
export function escapeNonAsciiCharacters(s: string): string {
// Replace non-ASCII characters with '\uNNNN' escapes if any exist.
Expand Down Expand Up @@ -1799,4 +1799,8 @@ module ts {
return (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) ||
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node);
}

export function getLocalSymbolForExportDefault(symbol: Symbol) {
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined;
}
}
10 changes: 9 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,14 @@ module ts {
return undefined;
}

// If this is the default export, get the name of the declaration if it exists
if (displayName === "default") {
let localSymbol = getLocalSymbolForExportDefault(symbol);
if (localSymbol && localSymbol.name) {
displayName = symbol.valueDeclaration.localSymbol.name;
}
}

let firstCharCode = displayName.charCodeAt(0);
// First check of the displayName is not external module; if it is an external module, it is not valid entry
if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
Expand Down Expand Up @@ -2675,7 +2683,7 @@ module ts {
previousToken.getStart() :
position;

let scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile);
let scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile;

/// TODO filter meaning based on the current context
let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias;
Expand Down
21 changes: 21 additions & 0 deletions tests/baselines/reference/APISample_linter.types.pull
Original file line number Diff line number Diff line change
Expand Up @@ -4984,6 +4984,27 @@ declare module "typescript" {
>CompilerHost : CompilerHost
>Program : Program
}
declare module "typescript" {
/**
* Read tsconfig.json file
* @param fileName The path to the config file
*/
function readConfigFile(fileName: string): any;
>readConfigFile : (fileName: string) => any
>fileName : string

/**
* Parse the contents of a config file (tsconfig.json).
* @param json The contents of the config file to parse
* @param basePath A root directory to resolve relative path entries in the config
* file to. e.g. outDir
*/
function parseConfigFile(json: any, basePath?: string): ParsedCommandLine;
>parseConfigFile : (json: any, basePath?: string) => ParsedCommandLine
>json : any
>basePath : string
>ParsedCommandLine : ParsedCommandLine
}
declare module "typescript" {
/** The version of the language service API */
let servicesVersion: string;
Expand Down
35 changes: 35 additions & 0 deletions tests/baselines/reference/es5ExportDefaultClassDeclaration3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [es5ExportDefaultClassDeclaration3.ts]

var before: C = new C();

export default class C {
method(): C {
return new C();
}
}

var after: C = new C();

var t: typeof C = C;



//// [es5ExportDefaultClassDeclaration3.js]
var before = new C();
var C = (function () {
function C() {
}
C.prototype.method = function () {
return new C();
};
return C;
})();
exports.default = C;
var after = new C();
var t = C;


//// [es5ExportDefaultClassDeclaration3.d.ts]
export default class C {
method(): C;
}
33 changes: 33 additions & 0 deletions tests/baselines/reference/es5ExportDefaultClassDeclaration3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/compiler/es5ExportDefaultClassDeclaration3.ts ===

var before: C = new C();
>before : C
>C : C
>new C() : C
>C : typeof C

export default class C {
>C : C

method(): C {
>method : () => C
>C : C

return new C();
>new C() : C
>C : typeof C
}
}

var after: C = new C();
>after : C
>C : C
>new C() : C
>C : typeof C

var t: typeof C = C;
>t : typeof C
>C : typeof C
>C : typeof C


21 changes: 21 additions & 0 deletions tests/baselines/reference/es5ExportDefaultFunctionDeclaration3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [es5ExportDefaultFunctionDeclaration3.ts]

var before: typeof func = func();

export default function func(): typeof func {
return func;
}

var after: typeof func = func();

//// [es5ExportDefaultFunctionDeclaration3.js]
var before = func();
function func() {
return func;
}
exports.default = func;
var after = func();


//// [es5ExportDefaultFunctionDeclaration3.d.ts]
export default function func(): typeof func;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration3.ts ===

var before: typeof func = func();
>before : () => typeof func
>func : () => typeof func
>func() : () => typeof func
>func : () => typeof func

export default function func(): typeof func {
>func : () => typeof func
>func : () => typeof func

return func;
>func : () => typeof func
}

var after: typeof func = func();
>after : () => typeof func
>func : () => typeof func
>func() : () => typeof func
>func : () => typeof func

16 changes: 16 additions & 0 deletions tests/cases/compiler/es5ExportDefaultClassDeclaration3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @target: es5
// @module: commonjs
// @declaration: true

var before: C = new C();

export default class C {
method(): C {
return new C();
}
}

var after: C = new C();

var t: typeof C = C;

11 changes: 11 additions & 0 deletions tests/cases/compiler/es5ExportDefaultFunctionDeclaration3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @target: es5
// @module: commonjs
// @declaration: true

var before: typeof func = func();

export default function func(): typeof func {
return func;
}

var after: typeof func = func();
12 changes: 12 additions & 0 deletions tests/cases/fourslash/exportDefaultClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path='./fourslash.ts'/>

////export default class C {
//// method() { /*1*/ }
////}
//// /*2*/

goTo.marker('1');
verify.completionListContains("C", "class C", /*documentation*/ undefined, "class");

goTo.marker('2');
verify.completionListContains("C", "class C", /*documentation*/ undefined, "class");
12 changes: 12 additions & 0 deletions tests/cases/fourslash/exportDefaultFunction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path='./fourslash.ts'/>

////export default function func() {
//// /*1*/
////}
//// /*2*/

goTo.marker('1');
verify.completionListContains("func", "function func(): void", /*documentation*/ undefined, "function");

goTo.marker('2');
verify.completionListContains("func", "function func(): void", /*documentation*/ undefined, "function");