mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
UMD support
This commit is contained in:
parent
b29f460641
commit
44aa7388ea
@ -1355,6 +1355,8 @@ namespace ts {
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
||||
case SyntaxKind.GlobalModuleExportDeclaration:
|
||||
return bindGlobalModuleExportDeclaration(<GlobalModuleExportDeclaration>node);
|
||||
case SyntaxKind.ImportClause:
|
||||
return bindImportClause(<ImportClause>node);
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
@ -1404,6 +1406,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function bindGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
|
||||
if (!file.externalModuleIndicator) {
|
||||
file.bindDiagnostics.push(createDiagnosticForNode(node, Diagnostics.Global_module_exports_may_only_appear_in_module_files));
|
||||
return;
|
||||
}
|
||||
file.symbol.globalExports = file.symbol.globalExports || {};
|
||||
declareSymbol(file.symbol.globalExports, file.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes);
|
||||
}
|
||||
|
||||
function bindExportDeclaration(node: ExportDeclaration) {
|
||||
if (!container.symbol || !container.symbol.exports) {
|
||||
// Export * in some sort of block construct
|
||||
|
||||
@ -981,6 +981,10 @@ namespace ts {
|
||||
return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node);
|
||||
}
|
||||
|
||||
function getTargetOfGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration): Symbol {
|
||||
return node.parent.symbol;
|
||||
}
|
||||
|
||||
function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol {
|
||||
return (<ExportDeclaration>node.parent.parent).moduleSpecifier ?
|
||||
getExternalModuleMember(<ExportDeclaration>node.parent.parent, node) :
|
||||
@ -1005,6 +1009,8 @@ namespace ts {
|
||||
return getTargetOfExportSpecifier(<ExportSpecifier>node);
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return getTargetOfExportAssignment(<ExportAssignment>node);
|
||||
case SyntaxKind.GlobalModuleExportDeclaration:
|
||||
return getTargetOfGlobalModuleExportDeclaration(<GlobalModuleExportDeclaration>node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15220,6 +15226,23 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration) {
|
||||
if (node.modifiers && node.modifiers.length) {
|
||||
error(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
|
||||
if (node.parent.kind !== SyntaxKind.SourceFile) {
|
||||
error(node, Diagnostics.Global_module_exports_may_only_appear_at_top_level);
|
||||
}
|
||||
else {
|
||||
const parent = node.parent as SourceFile;
|
||||
// Note: the binder handles the case where the declaration isn't in an external module
|
||||
if (parent.externalModuleIndicator && !parent.isDeclarationFile) {
|
||||
error(node, Diagnostics.Global_module_exports_may_only_appear_in_declaration_files);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function checkSourceElement(node: Node): void {
|
||||
if (!node) {
|
||||
@ -15337,6 +15360,8 @@ namespace ts {
|
||||
return checkExportDeclaration(<ExportDeclaration>node);
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return checkExportAssignment(<ExportAssignment>node);
|
||||
case SyntaxKind.GlobalModuleExportDeclaration:
|
||||
return checkGlobalModuleExportDeclaration(<GlobalModuleExportDeclaration>node);
|
||||
case SyntaxKind.EmptyStatement:
|
||||
checkGrammarStatementInAmbientContext(node);
|
||||
return;
|
||||
@ -16331,6 +16356,9 @@ namespace ts {
|
||||
if (file.moduleAugmentations.length) {
|
||||
(augmentations || (augmentations = [])).push(file.moduleAugmentations);
|
||||
}
|
||||
if (file.wasReferenced && file.symbol && file.symbol.globalExports) {
|
||||
mergeSymbolTable(globals, file.symbol.globalExports);
|
||||
}
|
||||
});
|
||||
|
||||
if (augmentations) {
|
||||
|
||||
@ -831,6 +831,18 @@
|
||||
"category": "Error",
|
||||
"code": 1313
|
||||
},
|
||||
"Global module exports may only appear in module files.": {
|
||||
"category": "Error",
|
||||
"code": 1314
|
||||
},
|
||||
"Global module exports may only appear in declaration files.": {
|
||||
"category": "Error",
|
||||
"code": 1315
|
||||
},
|
||||
"Global module exports may only appear at top level.": {
|
||||
"category": "Error",
|
||||
"code": 1316
|
||||
},
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
|
||||
@ -301,6 +301,9 @@ namespace ts {
|
||||
case SyntaxKind.ImportClause:
|
||||
return visitNode(cbNode, (<ImportClause>node).name) ||
|
||||
visitNode(cbNode, (<ImportClause>node).namedBindings);
|
||||
case SyntaxKind.GlobalModuleExportDeclaration:
|
||||
return visitNode(cbNode, (<GlobalModuleExportDeclaration>node).name);
|
||||
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return visitNode(cbNode, (<NamespaceImport>node).name);
|
||||
case SyntaxKind.NamedImports:
|
||||
@ -1125,7 +1128,7 @@ namespace ts {
|
||||
if (token === SyntaxKind.DefaultKeyword) {
|
||||
return lookAhead(nextTokenIsClassOrFunction);
|
||||
}
|
||||
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
}
|
||||
if (token === SyntaxKind.DefaultKeyword) {
|
||||
return nextTokenIsClassOrFunction();
|
||||
@ -4400,7 +4403,8 @@ namespace ts {
|
||||
continue;
|
||||
|
||||
case SyntaxKind.GlobalKeyword:
|
||||
return nextToken() === SyntaxKind.OpenBraceToken;
|
||||
nextToken();
|
||||
return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.Identifier || token === SyntaxKind.ExportKeyword;
|
||||
|
||||
case SyntaxKind.ImportKeyword:
|
||||
nextToken();
|
||||
@ -4409,7 +4413,8 @@ namespace ts {
|
||||
case SyntaxKind.ExportKeyword:
|
||||
nextToken();
|
||||
if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken ||
|
||||
token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword) {
|
||||
token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword ||
|
||||
token === SyntaxKind.AsKeyword) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
@ -4586,6 +4591,7 @@ namespace ts {
|
||||
case SyntaxKind.EnumKeyword:
|
||||
return parseEnumDeclaration(fullStart, decorators, modifiers);
|
||||
case SyntaxKind.GlobalKeyword:
|
||||
return parseModuleDeclaration(fullStart, decorators, modifiers);
|
||||
case SyntaxKind.ModuleKeyword:
|
||||
case SyntaxKind.NamespaceKeyword:
|
||||
return parseModuleDeclaration(fullStart, decorators, modifiers);
|
||||
@ -4593,9 +4599,15 @@ namespace ts {
|
||||
return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers);
|
||||
case SyntaxKind.ExportKeyword:
|
||||
nextToken();
|
||||
return token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken ?
|
||||
parseExportAssignment(fullStart, decorators, modifiers) :
|
||||
parseExportDeclaration(fullStart, decorators, modifiers);
|
||||
switch (token) {
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
case SyntaxKind.EqualsToken:
|
||||
return parseExportAssignment(fullStart, decorators, modifiers);
|
||||
case SyntaxKind.AsKeyword:
|
||||
return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers);
|
||||
default:
|
||||
return parseExportDeclaration(fullStart, decorators, modifiers);
|
||||
}
|
||||
default:
|
||||
if (decorators || modifiers) {
|
||||
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
|
||||
@ -5264,6 +5276,20 @@ namespace ts {
|
||||
return nextToken() === SyntaxKind.SlashToken;
|
||||
}
|
||||
|
||||
function parseGlobalModuleExportDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): GlobalModuleExportDeclaration {
|
||||
const exportDeclaration = <GlobalModuleExportDeclaration>createNode(SyntaxKind.GlobalModuleExportDeclaration, fullStart);
|
||||
exportDeclaration.decorators = decorators;
|
||||
exportDeclaration.modifiers = modifiers;
|
||||
parseExpected(SyntaxKind.AsKeyword);
|
||||
parseExpected(SyntaxKind.NamespaceKeyword);
|
||||
|
||||
exportDeclaration.name = parseIdentifier();
|
||||
|
||||
parseExpected(SyntaxKind.SemicolonToken);
|
||||
|
||||
return finishNode(exportDeclaration);
|
||||
}
|
||||
|
||||
function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration {
|
||||
parseExpected(SyntaxKind.ImportKeyword);
|
||||
const afterImportPos = scanner.getStartPos();
|
||||
|
||||
@ -1282,7 +1282,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function processRootFile(fileName: string, isDefaultLib: boolean) {
|
||||
processSourceFile(normalizePath(fileName), isDefaultLib);
|
||||
processSourceFile(normalizePath(fileName), isDefaultLib, /*isReference*/ true);
|
||||
}
|
||||
|
||||
function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
|
||||
@ -1376,7 +1376,10 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
/**
|
||||
* 'isReference' indicates whether the file was brought in via a reference directive (rather than an import declaration)
|
||||
*/
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, isReference: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
let diagnosticArgument: string[];
|
||||
let diagnostic: DiagnosticMessage;
|
||||
if (hasExtension(fileName)) {
|
||||
@ -1384,7 +1387,7 @@ namespace ts {
|
||||
diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1;
|
||||
diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"];
|
||||
}
|
||||
else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd)) {
|
||||
else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd)) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
diagnosticArgument = [fileName];
|
||||
}
|
||||
@ -1394,13 +1397,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
const nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd);
|
||||
const nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd);
|
||||
if (!nonTsFile) {
|
||||
if (options.allowNonTsExtensions) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
diagnosticArgument = [fileName];
|
||||
}
|
||||
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd))) {
|
||||
else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd))) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
fileName += ".ts";
|
||||
diagnosticArgument = [fileName];
|
||||
@ -1429,7 +1432,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Get source file from normalized fileName
|
||||
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
|
||||
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, isReference: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
|
||||
if (filesByName.contains(path)) {
|
||||
const file = filesByName.get(path);
|
||||
// try to check if we've already seen this file but with a different casing in path
|
||||
@ -1438,6 +1441,10 @@ namespace ts {
|
||||
reportFileNamesDifferOnlyInCasingError(fileName, file.fileName, refFile, refPos, refEnd);
|
||||
}
|
||||
|
||||
if (file) {
|
||||
file.wasReferenced = file.wasReferenced || isReference;
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@ -1454,6 +1461,7 @@ namespace ts {
|
||||
|
||||
filesByName.set(path, file);
|
||||
if (file) {
|
||||
file.wasReferenced = file.wasReferenced || isReference;
|
||||
file.path = path;
|
||||
|
||||
if (host.useCaseSensitiveFileNames()) {
|
||||
@ -1491,7 +1499,7 @@ namespace ts {
|
||||
function processReferencedFiles(file: SourceFile, basePath: string) {
|
||||
forEach(file.referencedFiles, ref => {
|
||||
const referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
|
||||
processSourceFile(referencedFileName, /*isDefaultLib*/ false, file, ref.pos, ref.end);
|
||||
processSourceFile(referencedFileName, /*isDefaultLib*/ false, /*isReference*/ true, file, ref.pos, ref.end);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1517,7 +1525,7 @@ namespace ts {
|
||||
i < file.imports.length;
|
||||
|
||||
if (shouldAddFile) {
|
||||
const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
|
||||
const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, /*isReference*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end);
|
||||
|
||||
if (importedFile && resolution.isExternalLibraryImport) {
|
||||
// Since currently irrespective of allowJs, we only look for supportedTypeScript extension external module files,
|
||||
|
||||
@ -274,6 +274,7 @@ namespace ts {
|
||||
ModuleDeclaration,
|
||||
ModuleBlock,
|
||||
CaseBlock,
|
||||
GlobalModuleExportDeclaration,
|
||||
ImportEqualsDeclaration,
|
||||
ImportDeclaration,
|
||||
ImportClause,
|
||||
@ -1324,6 +1325,12 @@ namespace ts {
|
||||
name: Identifier;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.GlobalModuleImport)
|
||||
export interface GlobalModuleExportDeclaration extends DeclarationStatement {
|
||||
name: Identifier;
|
||||
moduleReference: LiteralLikeNode;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.ExportDeclaration)
|
||||
export interface ExportDeclaration extends DeclarationStatement {
|
||||
exportClause?: NamedExports;
|
||||
@ -1537,6 +1544,8 @@ namespace ts {
|
||||
/* @internal */ externalModuleIndicator: Node;
|
||||
// The first node that causes this file to be a CommonJS module
|
||||
/* @internal */ commonJsModuleIndicator: Node;
|
||||
// True if the file was a root file in a compilation or a /// reference targets
|
||||
/* @internal */ wasReferenced?: boolean;
|
||||
|
||||
/* @internal */ identifiers: Map<string>;
|
||||
/* @internal */ nodeCount: number;
|
||||
@ -1995,6 +2004,7 @@ namespace ts {
|
||||
|
||||
members?: SymbolTable; // Class, interface or literal instance members
|
||||
exports?: SymbolTable; // Module exports
|
||||
globalExports?: SymbolTable; // Conditional global UMD exports
|
||||
/* @internal */ id?: number; // Unique id (used to look up SymbolLinks)
|
||||
/* @internal */ mergeId?: number; // Merge id (used to look up merged symbol)
|
||||
/* @internal */ parent?: Symbol; // Parent symbol
|
||||
|
||||
@ -1471,6 +1471,7 @@ namespace ts {
|
||||
// export default ...
|
||||
export function isAliasSymbolDeclaration(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.ImportEqualsDeclaration ||
|
||||
node.kind === SyntaxKind.GlobalModuleExportDeclaration ||
|
||||
node.kind === SyntaxKind.ImportClause && !!(<ImportClause>node).name ||
|
||||
node.kind === SyntaxKind.NamespaceImport ||
|
||||
node.kind === SyntaxKind.ImportSpecifier ||
|
||||
|
||||
@ -88,7 +88,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
toBeCompiled = [];
|
||||
otherFiles = [];
|
||||
|
||||
if (/require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
|
||||
if (testCaseContent.settings["noImplicitReferences"] || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
|
||||
toBeCompiled.push({ unitName: this.makeUnitName(lastUnit.name, rootDir), content: lastUnit.content });
|
||||
units.forEach(unit => {
|
||||
if (unit.name !== lastUnit.name) {
|
||||
|
||||
@ -896,7 +896,8 @@ namespace Harness {
|
||||
{ name: "fileName", type: "string" },
|
||||
{ name: "libFiles", type: "string" },
|
||||
{ name: "noErrorTruncation", type: "boolean" },
|
||||
{ name: "suppressOutputPathCheck", type: "boolean" }
|
||||
{ name: "suppressOutputPathCheck", type: "boolean" },
|
||||
{ name: "noImplicitReferences", type: "boolean" }
|
||||
];
|
||||
|
||||
let optionsIndex: ts.Map<ts.CommandLineOption>;
|
||||
|
||||
60
tests/baselines/reference/umd-errors.errors.txt
Normal file
60
tests/baselines/reference/umd-errors.errors.txt
Normal file
@ -0,0 +1,60 @@
|
||||
tests/cases/conformance/externalModules/err1.d.ts(3,1): error TS1314: Global module exports may only appear in module files.
|
||||
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1314: Global module exports may only appear in module files.
|
||||
tests/cases/conformance/externalModules/err2.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
|
||||
tests/cases/conformance/externalModules/err3.d.ts(3,1): error TS1184: Modifiers cannot appear here.
|
||||
tests/cases/conformance/externalModules/err3.d.ts(4,1): error TS1184: Modifiers cannot appear here.
|
||||
tests/cases/conformance/externalModules/err3.d.ts(5,1): error TS1184: Modifiers cannot appear here.
|
||||
tests/cases/conformance/externalModules/err3.d.ts(6,7): error TS1134: Variable declaration expected.
|
||||
tests/cases/conformance/externalModules/err4.d.ts(3,2): error TS1316: Global module exports may only appear at top level.
|
||||
tests/cases/conformance/externalModules/err5.ts(3,1): error TS1315: Global module exports may only appear in declaration files.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/err1.d.ts (1 errors) ====
|
||||
|
||||
// Illegal, can't be in script file
|
||||
export as namespace Foo;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1314: Global module exports may only appear in module files.
|
||||
|
||||
==== tests/cases/conformance/externalModules/err2.d.ts (2 errors) ====
|
||||
// Illegal, can't be in external ambient module
|
||||
declare module "Foo" {
|
||||
export as namespace Bar;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1314: Global module exports may only appear in module files.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1316: Global module exports may only appear at top level.
|
||||
}
|
||||
|
||||
==== tests/cases/conformance/externalModules/err3.d.ts (4 errors) ====
|
||||
// Illegal, can't have modifiers
|
||||
export var p;
|
||||
static export as namespace oo1;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1184: Modifiers cannot appear here.
|
||||
declare export as namespace oo2;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1184: Modifiers cannot appear here.
|
||||
public export as namespace oo3;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1184: Modifiers cannot appear here.
|
||||
const export as namespace oo4;
|
||||
~~~~~~
|
||||
!!! error TS1134: Variable declaration expected.
|
||||
|
||||
==== tests/cases/conformance/externalModules/err4.d.ts (1 errors) ====
|
||||
// Illegal, must be at top-level
|
||||
export namespace B {
|
||||
export as namespace C1;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1316: Global module exports may only appear at top level.
|
||||
}
|
||||
|
||||
==== tests/cases/conformance/externalModules/err5.ts (1 errors) ====
|
||||
// Illegal, may not appear in implementation files
|
||||
export var v;
|
||||
export as namespace C2;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1315: Global module exports may only appear in declaration files.
|
||||
|
||||
|
||||
36
tests/baselines/reference/umd-errors.js
Normal file
36
tests/baselines/reference/umd-errors.js
Normal file
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/externalModules/umd-errors.ts] ////
|
||||
|
||||
//// [err1.d.ts]
|
||||
|
||||
// Illegal, can't be in script file
|
||||
export as namespace Foo;
|
||||
|
||||
//// [err2.d.ts]
|
||||
// Illegal, can't be in external ambient module
|
||||
declare module "Foo" {
|
||||
export as namespace Bar;
|
||||
}
|
||||
|
||||
//// [err3.d.ts]
|
||||
// Illegal, can't have modifiers
|
||||
export var p;
|
||||
static export as namespace oo1;
|
||||
declare export as namespace oo2;
|
||||
public export as namespace oo3;
|
||||
const export as namespace oo4;
|
||||
|
||||
//// [err4.d.ts]
|
||||
// Illegal, must be at top-level
|
||||
export namespace B {
|
||||
export as namespace C1;
|
||||
}
|
||||
|
||||
//// [err5.ts]
|
||||
// Illegal, may not appear in implementation files
|
||||
export var v;
|
||||
export as namespace C2;
|
||||
|
||||
|
||||
|
||||
//// [err5.js]
|
||||
"use strict";
|
||||
8
tests/baselines/reference/umd-errors.symbols
Normal file
8
tests/baselines/reference/umd-errors.symbols
Normal file
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/externalModules/err5.d.ts ===
|
||||
// Illegal, may not appear in implementation files
|
||||
export var v;
|
||||
>v : Symbol(v, Decl(err5.d.ts, 1, 10))
|
||||
|
||||
export as namespace C;
|
||||
|
||||
|
||||
9
tests/baselines/reference/umd-errors.types
Normal file
9
tests/baselines/reference/umd-errors.types
Normal file
@ -0,0 +1,9 @@
|
||||
=== tests/cases/conformance/externalModules/err5.d.ts ===
|
||||
// Illegal, may not appear in implementation files
|
||||
export var v;
|
||||
>v : any
|
||||
|
||||
export as namespace C;
|
||||
>C : any
|
||||
|
||||
|
||||
21
tests/baselines/reference/umd1.js
Normal file
21
tests/baselines/reference/umd1.js
Normal file
@ -0,0 +1,21 @@
|
||||
//// [tests/cases/conformance/externalModules/umd1.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
/// <reference path="foo.d.ts" />
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
/// <reference path="foo.d.ts" />
|
||||
exports.Foo.fn();
|
||||
var x;
|
||||
var y = x.n;
|
||||
33
tests/baselines/reference/umd1.symbols
Normal file
33
tests/baselines/reference/umd1.symbols
Normal file
@ -0,0 +1,33 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
/// <reference path="foo.d.ts" />
|
||||
Foo.fn();
|
||||
>Foo.fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
|
||||
>fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
let x: Foo.Thing;
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 38))
|
||||
>Thing : Symbol(Foo.Thing, Decl(foo.d.ts, 2, 27))
|
||||
|
||||
let y: number = x.n;
|
||||
>y : Symbol(y, Decl(a.ts, 3, 3))
|
||||
>x.n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export function fn(): void;
|
||||
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
|
||||
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
|
||||
35
tests/baselines/reference/umd1.types
Normal file
35
tests/baselines/reference/umd1.types
Normal file
@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
/// <reference path="foo.d.ts" />
|
||||
Foo.fn();
|
||||
>Foo.fn() : void
|
||||
>Foo.fn : () => void
|
||||
>Foo : typeof Foo
|
||||
>fn : () => void
|
||||
|
||||
let x: Foo.Thing;
|
||||
>x : Foo.Thing
|
||||
>Foo : any
|
||||
>Thing : Foo.Thing
|
||||
|
||||
let y: number = x.n;
|
||||
>y : number
|
||||
>x.n : number
|
||||
>x : Foo.Thing
|
||||
>n : number
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : number
|
||||
|
||||
export function fn(): void;
|
||||
>fn : () => void
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Thing
|
||||
>n : number
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
|
||||
19
tests/baselines/reference/umd2.errors.txt
Normal file
19
tests/baselines/reference/umd2.errors.txt
Normal file
@ -0,0 +1,19 @@
|
||||
tests/cases/conformance/externalModules/a.ts(1,1): error TS2304: Cannot find name 'Foo'.
|
||||
tests/cases/conformance/externalModules/a.ts(2,8): error TS2503: Cannot find namespace 'Foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/a.ts (2 errors) ====
|
||||
Foo.fn();
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'Foo'.
|
||||
let x: Foo.Thing;
|
||||
~~~
|
||||
!!! error TS2503: Cannot find namespace 'Foo'.
|
||||
let y: number = x.n;
|
||||
|
||||
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export as namespace Foo;
|
||||
|
||||
18
tests/baselines/reference/umd2.js
Normal file
18
tests/baselines/reference/umd2.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [tests/cases/conformance/externalModules/umd2.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
Foo.fn();
|
||||
var x;
|
||||
var y = x.n;
|
||||
22
tests/baselines/reference/umd3.js
Normal file
22
tests/baselines/reference/umd3.js
Normal file
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/conformance/externalModules/umd3.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
import * as Foo from './foo';
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var Foo = require('./foo');
|
||||
Foo.fn();
|
||||
var x;
|
||||
var y = x.n;
|
||||
35
tests/baselines/reference/umd3.symbols
Normal file
35
tests/baselines/reference/umd3.symbols
Normal file
@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
import * as Foo from './foo';
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
|
||||
|
||||
Foo.fn();
|
||||
>Foo.fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
|
||||
>fn : Symbol(Foo.fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
let x: Foo.Thing;
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 6))
|
||||
>Thing : Symbol(Foo.Thing, Decl(foo.d.ts, 2, 27))
|
||||
|
||||
let y: number = x.n;
|
||||
>y : Symbol(y, Decl(a.ts, 3, 3))
|
||||
>x.n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>n : Symbol(Foo.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export function fn(): void;
|
||||
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
|
||||
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
|
||||
37
tests/baselines/reference/umd3.types
Normal file
37
tests/baselines/reference/umd3.types
Normal file
@ -0,0 +1,37 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
import * as Foo from './foo';
|
||||
>Foo : typeof Foo
|
||||
|
||||
Foo.fn();
|
||||
>Foo.fn() : void
|
||||
>Foo.fn : () => void
|
||||
>Foo : typeof Foo
|
||||
>fn : () => void
|
||||
|
||||
let x: Foo.Thing;
|
||||
>x : Foo.Thing
|
||||
>Foo : any
|
||||
>Thing : Foo.Thing
|
||||
|
||||
let y: number = x.n;
|
||||
>y : number
|
||||
>x.n : number
|
||||
>x : Foo.Thing
|
||||
>n : number
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : number
|
||||
|
||||
export function fn(): void;
|
||||
>fn : () => void
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Thing
|
||||
>n : number
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
|
||||
22
tests/baselines/reference/umd4.js
Normal file
22
tests/baselines/reference/umd4.js
Normal file
@ -0,0 +1,22 @@
|
||||
//// [tests/cases/conformance/externalModules/umd4.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
import * as Bar from './foo';
|
||||
Bar.fn();
|
||||
let x: Bar.Thing;
|
||||
let y: number = x.n;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var Bar = require('./foo');
|
||||
Bar.fn();
|
||||
var x;
|
||||
var y = x.n;
|
||||
35
tests/baselines/reference/umd4.symbols
Normal file
35
tests/baselines/reference/umd4.symbols
Normal file
@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
import * as Bar from './foo';
|
||||
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
|
||||
|
||||
Bar.fn();
|
||||
>Bar.fn : Symbol(Bar.fn, Decl(foo.d.ts, 1, 21))
|
||||
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
|
||||
>fn : Symbol(Bar.fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
let x: Bar.Thing;
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>Bar : Symbol(Bar, Decl(a.ts, 0, 6))
|
||||
>Thing : Symbol(Bar.Thing, Decl(foo.d.ts, 2, 27))
|
||||
|
||||
let y: number = x.n;
|
||||
>y : Symbol(y, Decl(a.ts, 3, 3))
|
||||
>x.n : Symbol(Bar.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(a.ts, 2, 3))
|
||||
>n : Symbol(Bar.Thing.n, Decl(foo.d.ts, 3, 24))
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export function fn(): void;
|
||||
>fn : Symbol(fn, Decl(foo.d.ts, 1, 21))
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 2, 27))
|
||||
>n : Symbol(n, Decl(foo.d.ts, 3, 24))
|
||||
>x : Symbol(x, Decl(foo.d.ts, 1, 10))
|
||||
|
||||
export as namespace Foo;
|
||||
|
||||
37
tests/baselines/reference/umd4.types
Normal file
37
tests/baselines/reference/umd4.types
Normal file
@ -0,0 +1,37 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
import * as Bar from './foo';
|
||||
>Bar : typeof Bar
|
||||
|
||||
Bar.fn();
|
||||
>Bar.fn() : void
|
||||
>Bar.fn : () => void
|
||||
>Bar : typeof Bar
|
||||
>fn : () => void
|
||||
|
||||
let x: Bar.Thing;
|
||||
>x : Bar.Thing
|
||||
>Bar : any
|
||||
>Thing : Bar.Thing
|
||||
|
||||
let y: number = x.n;
|
||||
>y : number
|
||||
>x.n : number
|
||||
>x : Bar.Thing
|
||||
>n : number
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
|
||||
export var x: number;
|
||||
>x : number
|
||||
|
||||
export function fn(): void;
|
||||
>fn : () => void
|
||||
|
||||
export interface Thing { n: typeof x }
|
||||
>Thing : Thing
|
||||
>n : number
|
||||
>x : number
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : any
|
||||
|
||||
20
tests/baselines/reference/umd5.errors.txt
Normal file
20
tests/baselines/reference/umd5.errors.txt
Normal file
@ -0,0 +1,20 @@
|
||||
tests/cases/conformance/externalModules/a.ts(6,9): error TS2304: Cannot find name 'Foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/a.ts (1 errors) ====
|
||||
import * as Bar from './foo';
|
||||
Bar.fn();
|
||||
let x: Bar.Thing;
|
||||
let y: number = x.n;
|
||||
// should error
|
||||
let z = Foo;
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'Foo'.
|
||||
|
||||
==== tests/cases/conformance/externalModules/foo.d.ts (0 errors) ====
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
26
tests/baselines/reference/umd5.js
Normal file
26
tests/baselines/reference/umd5.js
Normal file
@ -0,0 +1,26 @@
|
||||
//// [tests/cases/conformance/externalModules/umd5.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
import * as Bar from './foo';
|
||||
Bar.fn();
|
||||
let x: Bar.Thing;
|
||||
let y: number = x.n;
|
||||
// should error
|
||||
let z = Foo;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var Bar = require('./foo');
|
||||
Bar.fn();
|
||||
var x;
|
||||
var y = x.n;
|
||||
// should error
|
||||
var z = Foo;
|
||||
31
tests/cases/conformance/externalModules/umd-errors.ts
Normal file
31
tests/cases/conformance/externalModules/umd-errors.ts
Normal file
@ -0,0 +1,31 @@
|
||||
// @module: commonjs
|
||||
|
||||
// @filename: err1.d.ts
|
||||
// Illegal, can't be in script file
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: err2.d.ts
|
||||
// Illegal, can't be in external ambient module
|
||||
declare module "Foo" {
|
||||
export as namespace Bar;
|
||||
}
|
||||
|
||||
// @filename: err3.d.ts
|
||||
// Illegal, can't have modifiers
|
||||
export var p;
|
||||
static export as namespace oo1;
|
||||
declare export as namespace oo2;
|
||||
public export as namespace oo3;
|
||||
const export as namespace oo4;
|
||||
|
||||
// @filename: err4.d.ts
|
||||
// Illegal, must be at top-level
|
||||
export namespace B {
|
||||
export as namespace C1;
|
||||
}
|
||||
|
||||
// @filename: err5.ts
|
||||
// Illegal, may not appear in implementation files
|
||||
export var v;
|
||||
export as namespace C2;
|
||||
|
||||
14
tests/cases/conformance/externalModules/umd1.ts
Normal file
14
tests/cases/conformance/externalModules/umd1.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
/// <reference path="foo.d.ts" />
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
12
tests/cases/conformance/externalModules/umd2.ts
Normal file
12
tests/cases/conformance/externalModules/umd2.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
14
tests/cases/conformance/externalModules/umd3.ts
Normal file
14
tests/cases/conformance/externalModules/umd3.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
import * as Foo from './foo';
|
||||
Foo.fn();
|
||||
let x: Foo.Thing;
|
||||
let y: number = x.n;
|
||||
14
tests/cases/conformance/externalModules/umd4.ts
Normal file
14
tests/cases/conformance/externalModules/umd4.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
import * as Bar from './foo';
|
||||
Bar.fn();
|
||||
let x: Bar.Thing;
|
||||
let y: number = x.n;
|
||||
16
tests/cases/conformance/externalModules/umd5.ts
Normal file
16
tests/cases/conformance/externalModules/umd5.ts
Normal file
@ -0,0 +1,16 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
export var x: number;
|
||||
export function fn(): void;
|
||||
export interface Thing { n: typeof x }
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
import * as Bar from './foo';
|
||||
Bar.fn();
|
||||
let x: Bar.Thing;
|
||||
let y: number = x.n;
|
||||
// should error
|
||||
let z = Foo;
|
||||
Loading…
x
Reference in New Issue
Block a user