-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
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);
Metadata
Metadata
Assignees
Labels
No labels