-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Merged
Merged
UMD support #7264
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
44aa738
UMD support
RyanCavanaugh e9f4bef
Address CR feedback
RyanCavanaugh 887adb0
Move checks from checker to binder
RyanCavanaugh 34cf105
Lint
RyanCavanaugh 132d75c
Support UMD when targeted module uses `export = `
RyanCavanaugh 3d948be
Support module augmentation
RyanCavanaugh 2875326
Use existing function to resolve export= declarations
RyanCavanaugh 14941f2
Add tests for each variant of UMD augmentation
RyanCavanaugh c72f1c3
Reuse existing var
RyanCavanaugh 8cef251
Add test for function export
RyanCavanaugh 043b338
Add `export = class` scenario
RyanCavanaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//// [tests/cases/conformance/externalModules/umd-augmentation-1.ts] //// | ||
|
||
//// [index.d.ts] | ||
|
||
export as namespace Math2d; | ||
|
||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export class Vector implements Point { | ||
x: number; | ||
y: number; | ||
constructor(x: number, y: number); | ||
|
||
translate(dx: number, dy: number): Vector; | ||
} | ||
|
||
export function getLength(p: Vector): number; | ||
|
||
//// [math2d-augment.d.ts] | ||
import * as Math2d from 'math2d'; | ||
// Augment the module | ||
declare module 'math2d' { | ||
// Add a method to the class | ||
interface Vector { | ||
reverse(): Math2d.Point; | ||
} | ||
} | ||
|
||
//// [b.ts] | ||
/// <reference path="math2d-augment.d.ts" /> | ||
import * as m from 'math2d'; | ||
let v = new m.Vector(3, 2); | ||
let magnitude = m.getLength(v); | ||
let p: m.Point = v.translate(5, 5); | ||
p = v.reverse(); | ||
var t = p.x; | ||
|
||
|
||
//// [b.js] | ||
"use strict"; | ||
/// <reference path="math2d-augment.d.ts" /> | ||
var m = require('math2d'); | ||
var v = new m.Vector(3, 2); | ||
var magnitude = m.getLength(v); | ||
var p = v.translate(5, 5); | ||
p = v.reverse(); | ||
var t = p.x; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
parent
here