Skip to content

Commit

Permalink
Sync REPL and browser loader to version and /loader changes
Browse files Browse the repository at this point in the history
When the TraceurLoader files were moved from `/runtime` to `'/loader` a few browser-oriented uses were missed.

When `System` was removed as a global, a few too many calls were changed to point to `ModuleStore`.
The bootstrap functions need to use `ModuleStore` (via `$traceurRuntime` as our single global entry). The calls within our loader should use `this`, not `ModuleStore`.

Review URL: https://api.github.com/repos/google/traceur-compiler/issues/2049

Closes #2049.
  • Loading branch information
johnjbarton committed Dec 30, 2015
1 parent 6ed2928 commit 8ecd536
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 56 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -96,6 +96,7 @@ test-runtime: bin/traceur-runtime.js $(RUNTIME_TESTS)
@echo 'Open test/runtime.html to test runtime only'

test: bin/traceur.js \
bin/BrowserSystem.js \
test/unit \
test/unit/runtime/traceur-runtime \
wiki test/amd-compiled test/commonjs-compiled test-interpret \
Expand Down Expand Up @@ -219,6 +220,9 @@ build/compiled-by-previous-traceur.js: src/loader/version.js \
debug: build/compiled-by-previous-traceur.js $(SRC)
./traceur --debug --out bin/traceur.js --sourcemap $(RUNTIME_SCRIPTS) $(TFLAGS) $(SRC)

bin/BrowserSystem.js: src/browser/System.js
./traceur --out $@ $(TFLAGS) $^

#
# Rules to test traceur.js compiled through path that first compiles out modules then es6.
# The regular compiler must be built before running these rules.
Expand Down
5 changes: 1 addition & 4 deletions demo/repl.html
Expand Up @@ -46,10 +46,7 @@
<script src="../third_party/CodeMirror-4.0.3/keymap/sublime.js"></script>

<script src="../bin/traceur.js"></script>
<script>
window.System = new traceur.runtime.BrowserTraceurLoader();
System.map = System.semverMap('traceur@' + System.version);
</script>
<script src="../bin/BrowserSystem.js"></script>

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Droid+Sans+Mono|Droid+Sans">

Expand Down
2 changes: 1 addition & 1 deletion demo/transcode.js
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {BrowserTraceurLoader} from 'traceur@0.0/src/runtime/TraceurLoader.js';
import {BrowserTraceurLoader} from 'traceur@0.0/src/loader/TraceurLoader.js';
import {ErrorReporter} from 'traceur@0.0/src/util/ErrorReporter.js';
import {
SourceMapGenerator,
Expand Down
7 changes: 5 additions & 2 deletions src/browser/System.js
Expand Up @@ -12,12 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {BrowserTraceurLoader} from '../runtime/TraceurLoader.js';
import {BrowserTraceurLoader} from '../loader/TraceurLoader.js';

let traceurLoader = new BrowserTraceurLoader();

Reflect.global.System = traceurLoader;

export { traceurLoader as System }

traceurLoader.map = traceurLoader.semverMap(__moduleName);
traceurLoader.map = traceurLoader.semverMap('traceur@' + traceurLoader.version);

$traceurRuntime.normalizeModuleName =
traceurLoader.normalize.bind(traceurLoader);
23 changes: 7 additions & 16 deletions src/loader/InternalLoader.js
Expand Up @@ -17,8 +17,6 @@ import {LoaderCompiler} from './LoaderCompiler.js';
import {ExportsList} from '../codegeneration/module/ModuleSymbol.js';
import {isAbsolute, resolveUrl} from '../util/url.js';
import {Options} from '../Options.js';
import {ModuleStore} from './ModuleStore.js';


var NOT_STARTED = 0;
var LOADING = 1;
Expand Down Expand Up @@ -146,7 +144,7 @@ class PreCompiledCodeUnit extends CodeUnit {
*/
class BundledCodeUnit extends CodeUnit {
constructor(loaderCompiler, normalizedName, name, referrerName, address,
deps, execute) {
deps, execute, setModule) {
super(loaderCompiler, normalizedName, 'module', TRANSFORMED,
name, referrerName, address);
this.deps = deps;
Expand All @@ -159,7 +157,7 @@ class BundledCodeUnit extends CodeUnit {
var normalizedNames =
this.deps.map((name) => this.loader_.normalize(name));
var module = this.execute.apply(Reflect.global, normalizedNames);
ModuleStore.setModule(this.normalizedName, module);
setModule(this.normalizedName, module);
return module;
}
}
Expand Down Expand Up @@ -327,7 +325,7 @@ export class InternalLoader {
* @param {string=} address, URL
*/
script(code, name, referrerName, address, metadata) {
var normalizedName = ModuleStore.normalize(name || '', referrerName, address);
var normalizedName = this.loader_.normalize(name || '', referrerName, address);
var codeUnit = new EvalCodeUnit(this.loaderCompiler, code, 'script',
normalizedName, referrerName, address);
var key = {};
Expand Down Expand Up @@ -355,7 +353,7 @@ export class InternalLoader {
}

getOrCreateCodeUnit_(name, referrerName, address, metadata) {
var normalizedName = ModuleStore.normalize(name, referrerName, address);
var normalizedName = this.loader_.normalize(name, referrerName, address);
// TODO(jjb): embed type in name per es-discuss Yehuda Katz,
// eg import 'name,script';
var type = 'module';
Expand All @@ -372,16 +370,9 @@ export class InternalLoader {
name, referrerName, address, module);
codeUnit.type = 'module';
} else {
var bundledModule = this.loader_.bundledModule(name);
if (bundledModule) {
codeUnit = new BundledCodeUnit(this.loaderCompiler, normalizedName,
name, referrerName, address,
bundledModule.deps, bundledModule.execute);
} else {
codeUnit = new LoadCodeUnit(this.loaderCompiler, normalizedName,
name, referrerName, address);
codeUnit.type = type;
}
codeUnit = new LoadCodeUnit(this.loaderCompiler, normalizedName,
name, referrerName, address);
codeUnit.type = type;
}
// We copy the incoming metadata to pass values from the API and to
// inherit value from the API call into modules imported by the root.
Expand Down
32 changes: 0 additions & 32 deletions test/modular/getTestLoader.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/runFeatureTests.js
Expand Up @@ -17,5 +17,5 @@
import {featureTestRunner} from './featureTestRunner.js';

featureTestRunner.run().catch((ex) => {
console.error('featureTestRunner FAILED ' + ex, ex.stack);
console.error('featureTestRunner FAILED ', ex.stack || ex);
});

0 comments on commit 8ecd536

Please sign in to comment.