-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dot notation in variable names (#30)
* Support dot notation in variable names import?abc.def.ghi=>1 => var abc = {}; abc.def = {}; abc.def.ghi = 1; import?window.jQuery=jquery => var window = {}; window.jQuery = require("jquery"); * Removed unnecessary append syntax * Special handling of "window" name Dot notation involving window is handled slightly different to not overwriting window properties import?window.jQuery=jquery => window = (window || {}); window.jQuery = require("jquery"); * Added mocha and tests for nested imports * Dont overwrite existing globals (removed special handling of 'window') Nested imports will not overwrite top level globals. Eg. import?abc.def=1 is compiled to var abc = (abc || {}); abc.def = 1; * Removed redundant tests
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var should = require("should"); | ||
var loader = require("../"); | ||
|
||
var HEADER = "/*** IMPORTS FROM imports-loader ***/\n"; | ||
|
||
describe("loader", function() { | ||
it("should import nested objects", function() { | ||
loader.call({ | ||
query: "?abc.def.ghi=>1" | ||
}, "").should.be.eql(HEADER + | ||
"var abc = (abc || {});\n" + | ||
"abc.def = {};\n" + | ||
"abc.def.ghi = 1;\n\n\n" | ||
); | ||
}); | ||
|
||
it("should import multiple nested objects", function() { | ||
loader.call({ | ||
query: "?abc.def.ghi=>1,foo.bar.baz=>2" | ||
}, "").should.be.eql(HEADER + | ||
// First import | ||
"var abc = (abc || {});\n" + | ||
"abc.def = {};\n" + | ||
"abc.def.ghi = 1;\n" + | ||
// Second import | ||
"var foo = (foo || {});\n" + | ||
"foo.bar = {};\n" + | ||
"foo.bar.baz = 2;\n\n\n" | ||
); | ||
}); | ||
}); |