Opened 8 years ago

Closed 8 years ago

#12519 closed defect (worksforme)

replacement of AMD with dojo.require/dojo.declare in dojo build cause syntax error

Reported by: zhangyp Owned by: Rawld Gill
Priority: high Milestone: 1.7
Component: BuildSystem Version: 1.6.0
Keywords: Cc:
Blocked By: Blocking:

Description

I am trying to build dojo.js layer which includes dojo.json. Here is the layer for dojo.js

{

name: "dojo.js", customBase: true, dependencies: [

"dojo._base.declare", "dojo._base.lang", "dojo._base.array", "dojo._base.window", "dojo._base.event", "dojo._base.connect", "dojo._base.html", "dojo._base.json"

]

}

However, it will cause the syntax error report of invalid return in dojo.json. Here is how dojo.json is defined using AMD. define("dojo/json", [], function(){

var hasJSON = typeof JSON != "undefined" var features = {

"json-parse": hasJSON, all the parsers work fine Firefox 3.5/Gecko 1.9 fails to use replacer in stringify properly https://bugzilla.mozilla.org/show_bug.cgi?id=509184

"json-stringify": hasJSON && JSON.stringify({a:0}, function(k,v){return v
1}) == '{"a":1}'

}; function has(feature){

return features[feature];

} if(has("json-stringify")){

return JSON;

}else{

......

}

The line of return JSON; tries to return JSON as dojo.json and it is correct because it is in the body of a function. When dojo utility build dojo.js layer, it tries to replace AMD with dojo.require and dojo.declare. Here is the code generated in dojo.js.uncompressed.js.

if(!dojo._hasResourcedojo.json?){ _hasResource checks added by build. Do not use _hasResource directly in your code. dojo._hasResourcedojo.json? = true; dojo.provide("dojo.json");

var hasJSON = typeof JSON != "undefined" var features = {

"json-parse": hasJSON, all the parsers work fine Firefox 3.5/Gecko 1.9 fails to use replacer in stringify properly https://bugzilla.mozilla.org/show_bug.cgi?id=509184

"json-stringify": hasJSON && JSON.stringify({a:0}, function(k,v){return v
1}) == '{"a":1}'

}; function has(feature){

return features[feature];

} if(has("json-stringify")){

return JSON;

} else{......}

The line of return JSON is invalid because it is not in the body of a function. I am not sure whether it is a bug of ShrinkSafe? but it is apparently a bug of dojo utility.

Change History (8)

comment:1 Changed 8 years ago by ben hockey

Resolution: invalid
Status: newclosed

dojo/json does not exist in the 1.6 release. you must be trying to use trunk - trunk is unstable from time to time and right now is one of those times. some of the code in trunk will not work with the current build system.

comment:2 Changed 8 years ago by zhangyp

Resolution: invalid
Status: closedreopened

Then would you transfer this ticket to someone who can help to fix the issue on the latest trunk? dojo.json is just an example to address the problem. The build system right now even breaks the test page like http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/form/test_Slider.html .

comment:3 Changed 8 years ago by bill

Owner: changed from Richard Backhouse to Rawld Gill
Status: reopenednew

Transferring to Rawld although I'm pretty sure he already has a ticket for the new AMD loader which will solve this.

comment:4 Changed 8 years ago by Rawld Gill

(In [24094]) temporarily repairs dojo/json, refs #12519

comment:5 Changed 8 years ago by Rawld Gill

Status: newassigned

When v1.6 is built, all AMD module expressions are replaced with dojo.provide/require. This also prevents passing AMD module values in the built code via the loader. The net effect is that if you want an AMD module to work in a v1.6 build, you've got to pass the AMD module value in some global variable.

This particular repair was accomplished by stuffing the dojo/json module variable into dojo.json.

Tested lightly on source and built version and seems OK.

This is a temporary repair. We'll revert the module back to its much-better original format once the 1.7 loader lands in trunk. Keeping ticket open until that time.

comment:6 Changed 8 years ago by bill

(In [24379]) Remove temporary closure added in [24094], it's no longer needed. Refs #12519, #12672 !strict.

comment:7 Changed 8 years ago by Rawld Gill

Component: ShrinkSafeBuildSystem
Milestone: tbd1.7

comment:8 Changed 8 years ago by Rawld Gill

Resolution: worksforme
Status: assignedclosed

I believe this report was against the v1.6 build system. Please try with trunk and reopen if you have a problem. I successfully built with the following profile:

dependencies = {
	layers:[{
		name: "dojo.js",
		customBase: true,
		dependencies: [
			"dojo._base.lang", "dojo._base.array", "dojo._base.window", "dojo._base.event", "dojo._base.connect", "dojo._base.html", "dojo._base.json"
		]
	}]
};
Note: See TracTickets for help on using tickets.