-
Notifications
You must be signed in to change notification settings - Fork 580
Extend TraceurLoader to BrowserTraceurLoader and NodeTraceurLoader. #1802
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
Conversation
@@ -287,4 +289,16 @@ export class TraceurLoader extends Loader { | |||
factoryFunction); | |||
} | |||
|
|||
static createLoader() { |
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.
Export this as a function instead?
export function createLoader() { ... }
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 like TraceurLoader.createLoader()
as API.
Travis failed. |
The Travis problem is likely issue #1804, commander version. |
5b42bbe
to
9958507
Compare
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {LoaderCompiler} from '../runtime/LoaderCompiler.js'; |
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.
Up until now src/node/** does not contain ES6. Maybe move this file to src/runtime/?
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.
Yes, that should work. The other distinction of src/node/
is that it is shipped in the npm package. But this file will be compiled in to bin/traceur.js
.
Done in next commit
LGTM |
I don't mean to intervene, but was just curious what use case this API provides over standard class instantiation? While I know it is a far off dream, ensuring minimal APIs added to the loader above those in the spec makes it more likely loaders will be interchangeable. |
The use case is to create a new Loader. I'm open to alternatives. Our loader uses a platform dependent fileLoader and base url, so these have to come from somewhere. |
Perhaps this could be done through |
Not into this code well enough to comment too deeply, but just wanted to mention my concerns over the API drift. |
This function detects whether it is running in browser or node and creates a loader for the appropriate environment. Its purpose is provide a platform-independent mechanism to create a Loader. That way code that needs a Loader does not need to add detection code every time. The use case is obtaining a Loader for testing. The System reference is not used, though it would be great is we had something on the standard for creating a secondary Loader. |
@johnjbarton the assumtion I've always made is that the local For creating a secondary loader we do have |
Where is that discussed? |
It's just how classes work? |
The discussion was from whatwg/loader#7. |
But here are the (lack of) arguments to the constructor specified? I did not know there was even any spec for a constructor. |
The fetch implementation is managed as a hook not a constructor argument - |
@@ -22,7 +22,7 @@ if (!data) | |||
throw new Error('Failed to import ' + filename); | |||
|
|||
module._compile(data, filename); | |||
|
|||
console.log('traceur ', traceur.runtime); |
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.
Accident?
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.
Yes, I had to commit to move the code to another machine. Still in progress.
8e1a535
to
4b16e4a
Compare
PTAL @guybedford Thanks for the input, better for sure. I'll try to clean up the code now, to see if I can move the |
} | ||
|
||
var traceurLoader = new TraceurLoader(fileLoader, url); | ||
let traceurLoader = new BrowserTraceurLoader(); |
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.
Is this correct? Now System is always the browser loader.
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.
src/node/System.js
is used in node code. Browser code gets this file by module loading. Maybe we need a src/browser/
to make this clearer?
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.
+1 to src/browser
…across platforms. The feature tests use a sepearate loader so es6-ifying them will be easier with a better loader creator.
87f8d63
to
85080e1
Compare
Adjust test paths for root base url
85080e1
to
7d7bd75
Compare
PTAL The browser tests don't work, but they've not worked for a bit and I'm working on that now. |
'import * as c from "./resources/test_c.js";\n' + | ||
'import * as a from "./test/unit/runtime/resources/test_a.js";\n' + | ||
'import * as b from "./test/unit/runtime/resources/test_b.js";\n' + | ||
'import * as c from "./rtest/unit/runtime/esources/test_c.js";\n' + |
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.
typo: rtest
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.
Done, I just remove the imports. This test was only to verify that we took the reject() path.
Add a prefix string on anonymous file names to make debugging them easier
LGTM |
Move src/runtime/System.js to src/browser/System.js.
Adjust test paths for root base url.
Test
new System.constructor()
to create a secondary loader.