-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Adding support for named AMD modules. #1158
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ module ts { | |
interface ReferenceComments { | ||
referencedFiles: FileReference[]; | ||
amdDependencies: string[]; | ||
amdModuleName: string; | ||
} | ||
|
||
export function getSourceFileOfNode(node: Node): SourceFile { | ||
|
@@ -4218,6 +4219,7 @@ module ts { | |
function processReferenceComments(): ReferenceComments { | ||
var referencedFiles: FileReference[] = []; | ||
var amdDependencies: string[] = []; | ||
var amdModuleName: string; | ||
commentRanges = []; | ||
token = scanner.scan(); | ||
|
||
|
@@ -4237,6 +4239,12 @@ module ts { | |
} | ||
} | ||
else { | ||
var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim; | ||
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); | ||
if(amdModuleNameMatchResult) { | ||
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. Report error for duplicate entry if !amdModuleName? |
||
amdModuleName = amdModuleNameMatchResult[2]; | ||
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. @mhegazy should we do any verification on amdModuleName user gave? Like it is all white spaces? all numbers? Should it always be identifier? 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. @gisenberg We need test cases for amdModuleName irrespective of what @mhegazy comes back with. 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. I think it is fine. user needs to opt in into this scheme, and i would consider it as the amd dependency, what you write is what you get. |
||
} | ||
|
||
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path\s*=\s*('|")(.+?)\1/gim; | ||
var amdDependencyMatchResult = amdDependencyRegEx.exec(comment); | ||
if (amdDependencyMatchResult) { | ||
|
@@ -4247,7 +4255,8 @@ module ts { | |
commentRanges = undefined; | ||
return { | ||
referencedFiles: referencedFiles, | ||
amdDependencies: amdDependencies | ||
amdDependencies: amdDependencies, | ||
amdModuleName: amdModuleName | ||
}; | ||
} | ||
|
||
|
@@ -4276,6 +4285,7 @@ module ts { | |
var referenceComments = processReferenceComments(); | ||
file.referencedFiles = referenceComments.referencedFiles; | ||
file.amdDependencies = referenceComments.amdDependencies; | ||
file.amdModuleName = referenceComments.amdModuleName; | ||
file.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); | ||
file.externalModuleIndicator = getExternalModuleIndicator(); | ||
file.nodeCount = nodeCount; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [amdModuleName1.ts] | ||
///<amd-module name='NamedModule'/> | ||
class Foo { | ||
x: number; | ||
constructor() { | ||
this.x = 5; | ||
} | ||
} | ||
export = Foo; | ||
|
||
|
||
//// [amdModuleName1.js] | ||
define("NamedModule", ["require", "exports"], function (require, exports) { | ||
///<amd-module name='NamedModule'/> | ||
var Foo = (function () { | ||
function Foo() { | ||
this.x = 5; | ||
} | ||
return Foo; | ||
})(); | ||
return Foo; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=== tests/cases/compiler/amdModuleName1.ts === | ||
///<amd-module name='NamedModule'/> | ||
class Foo { | ||
>Foo : Foo | ||
|
||
x: number; | ||
>x : number | ||
|
||
constructor() { | ||
this.x = 5; | ||
>this.x = 5 : number | ||
>this.x : number | ||
>this : Foo | ||
>x : number | ||
} | ||
} | ||
export = Foo; | ||
>Foo : Foo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//@module: amd | ||
///<amd-module name='NamedModule'/> | ||
class Foo { | ||
x: number; | ||
constructor() { | ||
this.x = 5; | ||
} | ||
} | ||
export = Foo; |
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.
i would add a \s* before amd in "<amd-module"
and probably the same for amd-dependency
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.
That's not legal xml. Xml cannot have a space between the < and the start of the name token.