What is the "format register" string for at the top of JavaScript files? What is the "format register" string for at the top of JavaScript files? angularjs angularjs

What is the "format register" string for at the top of JavaScript files?


By adding 'format register'; at the top of all ts files the issue seems to be resolved but I suppose that it only helps SystemJS understand/load the modules correctly..

It just reduces bug as stated. Here is the orignal conversation that got it started. But it just makes SystemJS Load correctly. Infact it got very known that SystemJS Made a module that made that not neccesary, by adding this:

System.config({  meta: { main: { format: 'register' } }});

That is explained more here.

Reason to use it.To conclude, "format register", is used to make sure SystemJS Loads its modules correctly, and in order! Hope this helped!


Great question, I was intrigued and didn't know myself so went an a quest.

It appears it's a way of ES5 code to support ES6 style modules.

System.register can be considered as a new module format designed to support the exact semantics of ES6 modules within ES5. It is a format that was developed out of collaboration and is supported as a module output in Traceur (as instantiate), Babel and TypeScript (as system). All dynamic binding and circular reference behaviors supported by ES6 modules are supported by this format. In this way it acts as a safe and comprehensive target format for the polyfill path into ES6 modules.

https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained

Example usage:

To add some more detail, here is an example in the angular 1.x upgrade notes, which shows the example of format register in action, but rather than a comment at the top of the file, it's instead in the config declaration.

System.config({ packages: { 'base/app/js': { defaultExtension: false, format: 'register',...

https://angular.io/docs/ts/latest/guide/upgrade.html

Reason to use it

When the module format is not set, automatic regular-expression-based detection is used. This module format detection is never completely accurate, but caters well for the majority use cases.

https://github.com/systemjs/systemjs/blob/master/docs/module-formats.md

Using "format register" at the top of the file is one of the ways which gives the format detection a hint.