-
Notifications
You must be signed in to change notification settings - Fork 12.9k
UMD support #7264
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
UMD support #7264
Changes from 1 commit
44aa738
e9f4bef
887adb0
34cf105
132d75c
3d948be
2875326
14941f2
c72f1c3
8cef251
043b338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -981,6 +981,10 @@ namespace ts { | |
return getExternalModuleMember(<ImportDeclaration>node.parent.parent.parent, node); | ||
} | ||
|
||
function getTargetOfGlobalModuleExportDeclaration(node: GlobalModuleExportDeclaration): Symbol { | ||
return node.parent.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. can this symbol be merged with anything? 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. Hrm, yes. You could have a module jquery.d.ts and then an augmentation of it in another file. I assume that has some impact here? 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. use |
||
} | ||
|
||
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); | ||
} | ||
} | ||
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. Spoke offline with @vladima. Add all of this to the binder. |
||
|
||
} | ||
|
||
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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,16 +4591,23 @@ namespace ts { | |
case SyntaxKind.EnumKeyword: | ||
return parseEnumDeclaration(fullStart, decorators, modifiers); | ||
case SyntaxKind.GlobalKeyword: | ||
return parseModuleDeclaration(fullStart, decorators, modifiers); | ||
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. You can let this fall through again. |
||
case SyntaxKind.ModuleKeyword: | ||
case SyntaxKind.NamespaceKeyword: | ||
return parseModuleDeclaration(fullStart, decorators, modifiers); | ||
case SyntaxKind.ImportKeyword: | ||
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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,15 +1376,18 @@ 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) { | ||
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. A little bit of documentation on this would be helpful. From a cursory glance, it doesn't seem obvious that this is differentiated from an import. Alternatively, make an enum. |
||
let diagnosticArgument: string[]; | ||
let diagnostic: DiagnosticMessage; | ||
if (hasExtension(fileName)) { | ||
if (!options.allowNonTsExtensions && !forEach(supportedExtensions, extension => fileExtensionIs(host.getCanonicalFileName(fileName), extension))) { | ||
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, | ||
|
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.
Use the appropriate helper function to check this that's been defined elsewhere.
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.
?
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.
Sorry, I meant use
isExternalModule
inutilities.ts
. Vlad mentioned it offhandedly and I was too lazy to look it up.