Skip to content

Fix lack of error on default export of nonexistant name #40094

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

Merged
merged 4 commits into from
Aug 17, 2020
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
11 changes: 6 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32215,11 +32215,8 @@ namespace ts {
}

if (symbol.parent) {
// run check once for the first declaration
if (getDeclarationOfKind(symbol, node.kind) === node) {
// run check on export symbol to check that modifiers agree across all exported declarations
checkFunctionOrConstructorSymbol(symbol);
}
// run check on export symbol to check that modifiers agree across all exported declarations
checkFunctionOrConstructorSymbol(symbol);
}
}

Expand Down Expand Up @@ -34397,6 +34394,7 @@ namespace ts {
const typeWithThis = getTypeWithThisArgument(type);
const staticType = <ObjectType>getTypeOfSymbol(symbol);
checkTypeParameterListsIdentical(symbol);
checkFunctionOrConstructorSymbol(symbol);
checkClassForDuplicateDeclarations(node);

// Only check for reserved static identifiers on non-ambient context.
Expand Down Expand Up @@ -35585,6 +35583,9 @@ namespace ts {
checkExpressionCached(node.expression);
}
}
else {
checkExpressionCached(node.expression); // doesn't resolve, check as expression to mark as error
}

if (getEmitDeclarations(compilerOptions)) {
collectLinkedAliases(node.expression as Identifier, /*setVisibility*/ true);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ namespace ts {
switch (node.kind) {
case SyntaxKind.ImportClause:
if ((node as ImportClause).isTypeOnly) {
diagnostics.push(createDiagnosticForNode(node.parent, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, "import type"));
diagnostics.push(createDiagnosticForNode(parent, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, "import type"));
return "skip";
}
break;
Expand Down
22 changes: 21 additions & 1 deletion src/harness/compilerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,29 @@ namespace compiler {
if (compilerOptions.skipDefaultLibCheck === undefined) compilerOptions.skipDefaultLibCheck = true;
if (compilerOptions.noErrorTruncation === undefined) compilerOptions.noErrorTruncation = true;

const preProgram = ts.createProgram(rootFiles || [], { ...compilerOptions, traceResolution: false }, host);
const preErrors = ts.getPreEmitDiagnostics(preProgram);

const program = ts.createProgram(rootFiles || [], compilerOptions, host);
const emitResult = program.emit();
const errors = ts.getPreEmitDiagnostics(program);
const postErrors = ts.getPreEmitDiagnostics(program);
const errors = (preErrors.length !== postErrors.length) ? [...postErrors,
ts.addRelatedInfo(
ts.createCompilerDiagnostic({
category: ts.DiagnosticCategory.Error,
code: -1,
key: "-1",
message: `Pre-emit (${preErrors.length}) and post-emit (${postErrors.length}) diagnostic counts do not match! This can indicate that a semantic _error_ was added by the emit resolver - such an error may not be reflected on the command line or in the editor, but may be captured in a baseline here!`
}),
ts.createCompilerDiagnostic({
category: ts.DiagnosticCategory.Error,
code: -1,
key: "-1",
message: `The excess diagnostics are:`
}),
...ts.filter(postErrors, p => !ts.some(preErrors, p2 => ts.compareDiagnostics(p, p2) === ts.Comparison.EqualTo))
)
] : postErrors;
return new CompilationResult(host, compilerOptions, program, emitResult, errors);
}
}
7 changes: 7 additions & 0 deletions tests/baselines/reference/exportDefaultMissingName.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests/cases/compiler/exportDefaultMissingName.ts(1,16): error TS2304: Cannot find name 'xyzzy'.


==== tests/cases/compiler/exportDefaultMissingName.ts (1 errors) ====
export default xyzzy;
~~~~~
!!! error TS2304: Cannot find name 'xyzzy'.
7 changes: 7 additions & 0 deletions tests/baselines/reference/exportDefaultMissingName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//// [exportDefaultMissingName.ts]
export default xyzzy;

//// [exportDefaultMissingName.js]
"use strict";
exports.__esModule = true;
exports["default"] = xyzzy;
3 changes: 3 additions & 0 deletions tests/baselines/reference/exportDefaultMissingName.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== tests/cases/compiler/exportDefaultMissingName.ts ===
export default xyzzy;
No type information for this code.
4 changes: 4 additions & 0 deletions tests/baselines/reference/exportDefaultMissingName.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== tests/cases/compiler/exportDefaultMissingName.ts ===
export default xyzzy;
>xyzzy : any

1 change: 1 addition & 0 deletions tests/cases/compiler/exportDefaultMissingName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default xyzzy;