Skip to content

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

Closed
wants to merge 8 commits into from

Conversation

johnjbarton
Copy link
Contributor

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.

@@ -287,4 +289,16 @@ export class TraceurLoader extends Loader {
factoryFunction);
}

static createLoader() {
Copy link
Collaborator

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() { ... }

Copy link
Contributor Author

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.

@arv
Copy link
Collaborator

arv commented Mar 10, 2015

Travis failed.

@johnjbarton
Copy link
Contributor Author

The Travis problem is likely issue #1804, commander version.

// See the License for the specific language governing permissions and
// limitations under the License.

import {LoaderCompiler} from '../runtime/LoaderCompiler.js';
Copy link
Collaborator

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/?

Copy link
Contributor Author

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

@arv
Copy link
Collaborator

arv commented Mar 11, 2015

LGTM

@guybedford
Copy link
Contributor

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.

@johnjbarton
Copy link
Contributor Author

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.

@guybedford
Copy link
Contributor

Perhaps this could be done through BrowserLoader and NodeLoader extending TraceurLoader, whose instances then get assigned to the System namespace in both environments?

@guybedford
Copy link
Contributor

Not into this code well enough to comment too deeply, but just wanted to mention my concerns over the API drift.

@johnjbarton
Copy link
Contributor Author

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.

@guybedford
Copy link
Contributor

@johnjbarton the assumtion I've always made is that the local System is an instance of the environment loader. This reference effectively then provides that in a way that will be provided by the spec.

For creating a secondary loader we do have new System.constructor for that.

@johnjbarton
Copy link
Contributor Author

For creating a secondary loader we do have new System.constructor for that.

Where is that discussed?

@guybedford
Copy link
Contributor

It's just how classes work?

@guybedford
Copy link
Contributor

The discussion was from whatwg/loader#7.

@johnjbarton
Copy link
Contributor Author

But here are the (lack of) arguments to the constructor specified? I did not know there was even any spec for a constructor.

@guybedford
Copy link
Contributor

The fetch implementation is managed as a hook not a constructor argument - loader.hook('fetch', implementation) is the current spec for this, which would then run within the constructor itself for the browser loader I think.

@@ -22,7 +22,7 @@ if (!data)
throw new Error('Failed to import ' + filename);

module._compile(data, filename);

console.log('traceur ', traceur.runtime);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accident?

Copy link
Contributor Author

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.

@johnjbarton johnjbarton changed the title Add TraceurLoader.createLoader() to simplify the creation of loaders acr... Extend TraceurLoader to BrowserTraceurLoader and NodeTraceurLoader. Mar 12, 2015
@johnjbarton
Copy link
Contributor Author

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 fileLoader out of the base class.

}

var traceurLoader = new TraceurLoader(fileLoader, url);
let traceurLoader = new BrowserTraceurLoader();
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.
@johnjbarton
Copy link
Contributor Author

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' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: rtest

Copy link
Contributor Author

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
@arv
Copy link
Collaborator

arv commented Mar 30, 2015

LGTM

@arv arv removed the in progress label Mar 31, 2015
@johnjbarton johnjbarton deleted the create-loader branch May 4, 2015 23:33
@johnjbarton johnjbarton restored the create-loader branch May 12, 2015 23:32
@johnjbarton johnjbarton deleted the create-loader branch January 29, 2016 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants