You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do realize that the SystemJS loader can be used with AMD and CommonJS modules. Is there any interest in outputting directly to the system module format?
I've seen in the contributing guidelines that features need to be marked as "approved" before being accepted. I hope this one gets approved :) Just out of boredom I did fork and begin implementing SystemJS module output. You can check it out at https://github.com/mikehaas763/TypeScript/tree/systemjs
Please do leave me comments and suggestions on it.
There are several similarities to how AMD modules are created so I'm thinking I should find an abstraction for those similarities and use it from both module types.
Mike Haas (@mikehaas763) you can send PRs against Vladimir Matveev (@vladima)'s branch; i think this would be a good way to collaborate on this. we need to discuss the proposal in the language design meeting (which we usually have weekly). it would be great if we have a PR ready as well.
Is this the only way to handle circular references in TypeScript at the moment? I understand that SystemJS supports circular references, but at the moment I often get errors in the class code if the base class comes from another module involved in a circular reference (because the base constructor hadn't been imported).
At the moment I'm using SystemJS and TypeScript together by using the CommonJS module output format.
Jamie Winder (@jamiewinder) with the new ES6 module syntax supported by TypeScript 1.5 you can get most of your circular references issues done.
e.g.
import{two}from"./module2";exportfunctionone(counter: number){two(counter);console.log(`in one ${counter}.`);}
import{one}from"./module1";exportfunctiontwo(counter: number){if(counter){one(--counter);}console.log(`in two ${counter}.`);}two(3);
running
tsc --m commonjs module2.ts
and
node module2.js
results in:
in two 0.
in one 0.
in two 0.
in one 1.
in two 1.
in one 2.
in two 2.
The reason is these module aliases will be rewrite by the TypeScript compiler, so my module1.js looks like:
varmodule2_1=require("./module2");functionone(counter){module2_1.two(counter);console.log("in one "+counter+".");}exports.one=one;
where all references to two is rewritten as module2_1.two.
The cases where you need systemJs support is cyclical references in the main module body (i.e. not wrapped in function and classes) and in practice these are really limited scenarios.
I'm using the TypeScript 1.5 Alpha with the ES6 module format. This is an example from an issue I raised on the SystemJS repo (though I'm not sure it's a SystemJS issue):
The result is an error in the TypeScript __extends function (for ClassB) where the prototype is being set to that of the base constructor function. This because the base constructor wasn't imported (was undefined).
To clarify, this is ES6 modules, using TypeScript 1.5-alpha to output them as CommonJS format modules, to then be imported with SystemJS. So it's difficult to say where the issue is!
EDIT: A reply to my issue on the SystemJS repo suggests that it's CommonJS that's responsible for this. So, again, I certainly hope we can see register support in the TS 1.5 release. 😄
That works for me (except I use require('typescript').ModuleKind.System. Using "system" should work too though because I believe it automatically maps strings to the underlying ModuleKind type. How did you install your local typescript in to node_modules? Are you using the latest master branch?
I don't target ES6, I just target the default (I believe ES3) so that maybe is causing an issue. If you have ES6 then what's the point of translating the modules from ES6 to ES5 System.register modules?
Mike Graham (@cmichaelgraham) Support for systemjs was added in gulp-typescript v2.7.0. It now reads all the options from the ModuleKind & ScriptTarget enums at runtime, so all module kinds are now supported.
Is it possible to get one bundled JS file with 'es5' as target and 'system' as module output using the out parameter? The only thing we need are System.register statements creating named modules in the output.
Activity
chicoxyzzy commentedon Apr 5, 2015
+1. would like to see System loader implemented
mikehaas763 commentedon Apr 5, 2015
I've seen in the contributing guidelines that features need to be marked as "approved" before being accepted. I hope this one gets approved :) Just out of boredom I did fork and begin implementing SystemJS module output. You can check it out at https://github.com/mikehaas763/TypeScript/tree/systemjs
Please do leave me comments and suggestions on it.
There are several similarities to how AMD modules are created so I'm thinking I should find an abstraction for those similarities and use it from both module types.
mikehaas763 commentedon Apr 5, 2015
The actual function that emits the module format is mostly just a copy of the amd one at this point. I'm currently using https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained as a specification of sort for how I need to actually create the module format.
mhegazy commentedon Apr 6, 2015
Mike Haas (@mikehaas763) We are currently considering adding UMD (#2605) module support. so would be looking into systemjs as well.
Vladimir Matveev (@vladima) has a change along the same lines as yours. it would be great if you can collaborate on getting systemjs PR ready.
mikehaas763 commentedon Apr 6, 2015
Vladimir Matveev (@vladima) what change is it that you're working on?
Mohamed Hegazy (@mhegazy) It'd be nice if the current UMD spec had support for system modules!
vladima commentedon Apr 6, 2015
In my branch https://github.com/Microsoft/TypeScript/tree/systemRegister I've added initial support for system emit, hoisting of variable\function declarations. Pending work: rewriting exports, adding tests
mhegazy commentedon Apr 6, 2015
Mike Haas (@mikehaas763) you can send PRs against Vladimir Matveev (@vladima)'s branch; i think this would be a good way to collaborate on this. we need to discuss the proposal in the language design meeting (which we usually have weekly). it would be great if we have a PR ready as well.
niemyjski commentedon Apr 16, 2015
+1
mikehaas763 commentedon Apr 21, 2015
Looks like vladima has submitted his PR for this. So System.register modules should be coming soon! 😄
mhegazy commentedon Apr 21, 2015
here is the PR: #2840
jamiewinder commentedon Apr 23, 2015
Is this the only way to handle circular references in TypeScript at the moment? I understand that SystemJS supports circular references, but at the moment I often get errors in the class code if the base class comes from another module involved in a circular reference (because the base constructor hadn't been imported).
At the moment I'm using SystemJS and TypeScript together by using the CommonJS module output format.
Hopefully we get to see this in TS1.5 :)
mhegazy commentedon Apr 23, 2015
Jamie Winder (@jamiewinder) with the new ES6 module syntax supported by TypeScript 1.5 you can get most of your circular references issues done.
e.g.
running
and
results in:
The reason is these module aliases will be rewrite by the TypeScript compiler, so my module1.js looks like:
where all references to
twois rewritten asmodule2_1.two.The cases where you need systemJs support is cyclical references in the main module body (i.e. not wrapped in function and classes) and in practice these are really limited scenarios.
jamiewinder commentedon Apr 24, 2015
I'm using the TypeScript 1.5 Alpha with the ES6 module format. This is an example from an issue I raised on the SystemJS repo (though I'm not sure it's a SystemJS issue):
mod-a.ts
mod-b.ts:
index.ts
The result is an error in the TypeScript __extends function (for ClassB) where the prototype is being set to that of the base constructor function. This because the base constructor wasn't imported (was undefined).
To clarify, this is ES6 modules, using TypeScript 1.5-alpha to output them as CommonJS format modules, to then be imported with SystemJS. So it's difficult to say where the issue is!
EDIT: A reply to my issue on the SystemJS repo suggests that it's CommonJS that's responsible for this. So, again, I certainly hope we can see register support in the TS 1.5 release. 😄
mhegazy commentedon Apr 24, 2015
I think the issue here is order of imports.. so modifying your index.ts, to:
i get:
mhegazy commentedon Apr 24, 2015
And for completeness, systemjs module output should handle this correctly.
mhegazy commentedon Apr 27, 2015
Covered by #2840
cmichaelgraham commentedon May 8, 2015
Mohamed Hegazy (@mhegazy) need help with compiler options, don't see
System.registerat top of generated.jsfiles...here's the gulp task (using Ivo Gabe de Wolff (@ivogabe)
gulp-typescript)getting close on typescript aurelia port --> gulp build
folders generated by gulp-typescript build !!!!!!!!
issue is no
System.registerin system buildgulp task for system register
reported issue: #2616 (comment)
.jsshowing noSystem.registergetting close on build
mikehaas763 commentedon May 8, 2015
Mike Graham (@cmichaelgraham)
That works for me (except I use
require('typescript').ModuleKind.System. Using "system" should work too though because I believe it automatically maps strings to the underlying ModuleKind type. How did you install your local typescript in to node_modules? Are you using the latest master branch?I don't target ES6, I just target the default (I believe ES3) so that maybe is causing an issue. If you have ES6 then what's the point of translating the modules from ES6 to ES5 System.register modules?
ivogabe commentedon May 8, 2015
Mike Graham (@cmichaelgraham) Support for systemjs was added in gulp-typescript v2.7.0. It now reads all the options from the ModuleKind & ScriptTarget enums at runtime, so all module kinds are now supported.
Lenne231 commentedon May 25, 2015
Is it possible to get one bundled JS file with 'es5' as target and 'system' as module output using the out parameter? The only thing we need are
System.registerstatements creating named modules in the output.mhegazy commentedon May 25, 2015
Lennart (@Lenne231) currently
--outdoes not support combining--module; in 1.6 this should be supported though.ericmdantas commentedon May 25, 2015
+1. I'm also interested in this.
Just out of curiosity, are you guys waiting for the stable 1.5 to release it?
mhegazy commentedon May 26, 2015
yes. we usually lock down on the release a few weeks before it is out publicly. so stay tuned.
ericmdantas commentedon May 26, 2015
Alright, thanks!
dsebastien commentedon Jun 14, 2015
+1 for being able to generate a bundle containing n system modules, that'll be sweet!