Skip to content
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

undefined in runtimeArgs generates invalid code #33

Open
nkovacs opened this issue Jul 4, 2017 · 0 comments
Open

undefined in runtimeArgs generates invalid code #33

nkovacs opened this issue Jul 4, 2017 · 0 comments

Comments

@nkovacs
Copy link
Contributor

nkovacs commented Jul 4, 2017

I was experimenting with globalizejs/globalize#720 when I found this.
If runtimeArgs contains undefined, the compiler will generate invalid code. E.g.:

var Globalize = require( "globalize" );
var globalizeCompiler = require('globalize-compiler');

Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor( "en" ) );

var GyMMMd = Globalize( "en" ).dateFormatter({ skeleton: "GyMMMd" });
GyMMMd.runtimeArgs.push(undefined);
GyMMMd.runtimeArgs.push(undefined);

var out = globalizeCompiler.compile([
    GyMMMd,
], {});

The generated code will look like this:

Globalize.b938155015 = dateFormatterFn({"1":Globalize("en").numberFormatter({"raw":"0"})}, {"pattern":"MMM d, y G","timeSeparator":":","months":{"M":{"3":{"1":"Jan","2":"Feb","3":"Mar","4":"Apr","5":"May","6":"Jun","7":"Jul","8":"Aug","9":"Sep","10":"Oct","11":"Nov","12":"Dec"}}},"eras":{"0":"BC","1":"AD","0-alt-variant":"BCE","1-alt-variant":"CE"}}, , );

The , , ); is a syntax error.

The replacement happens here: https://github.com/globalizejs/globalize-compiler/blob/v1.0.0/lib/compile.js#L142

I suspect this isn't likely to come up in real-world usage, but shouldn't the compiler generate undefined? i.e.:

Globalize.b938155015 = dateFormatterFn({"1":Globalize("en").numberFormatter({"raw":"0"})}, {"pattern":"MMM d, y G","timeSeparator":":","months":{"M":{"3":{"1":"Jan","2":"Feb","3":"Mar","4":"Apr","5":"May","6":"Jun","7":"Jul","8":"Aug","9":"Sep","10":"Oct","11":"Nov","12":"Dec"}}},"eras":{"0":"BC","1":"AD","0-alt-variant":"BCE","1-alt-variant":"CE"}}, undefined, undefined);
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

No branches or pull requests

1 participant