forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
223 lines (195 loc) · 6.39 KB
/
index.js
File metadata and controls
223 lines (195 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
it("should parse fancy function calls", function() {
("function"==typeof define && define.amd ?
define :
function(e,t){return t()}
)(["./constructor"], function(c) {
return new c(1324);
});
expect(module.exports).toHaveProperty("value", 1324);
(("function"==typeof define && define.amd ?
define :
function(e,t){return t()}
)(["./constructor"], function(c) {
return new c(4231);
}));
expect(module.exports).toHaveProperty("value", 4231);
});
it("should parse fancy AMD calls", function() {
require("./constructor ./a".split(" "));
require("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), function(require, module, exports, constructor, a) {
expect((typeof require)).toBe("function");
expect((typeof module)).toBe("object");
expect((typeof exports)).toBe("object");
expect((typeof require("./constructor"))).toBe("function");
expect((typeof constructor)).toBe("function");
expect(a).toBe("a");
});
define("-> module module exports *constructor *a".replace("module", "require").substr(3).replace(/\*/g, "./").split(" "), function(require, module, exports, constructor, a) {
expect((typeof require)).toBe("function");
expect((typeof module)).toBe("object");
expect((typeof exports)).toBe("object");
expect((typeof require("./constructor"))).toBe("function");
expect((typeof constructor)).toBe("function");
expect(a).toBe("a");
});
});
it("should be able to use AMD-style require", function(done) {
var template = "b";
require(["./circular", "./templates/" + template, true ? "./circular" : "fail"], function(circular, testTemplate, circular2) {
expect(circular).toBe(1);
expect(circular2).toBe(1);
expect(testTemplate).toBe("b");
done();
});
});
it("should be able to use require.js-style define", function(done) {
define("name", ["./circular"], function(circular) {
expect(circular).toBe(1);
done();
});
});
it("should be able to use require.js-style define, optional dependencies, not exist", function(done) {
define("name", ["./optional"], function(optional) {
expect(optional.b).toBeFalsy();
done();
});
});
it("should be able to use require.js-style define, special string", function(done) {
define(["require"], function(require) {
expect(require("./circular")).toBe(1);
done();
});
});
it("should be able to use require.js-style define, without name", function(done) {
true && define(["./circular"], function(circular) {
expect(circular).toBe(1);
done();
});
});
it("should be able to use require.js-style define, with empty dependencies", function(done) {
define("name", [], function() {
done();
});
});
it("should be able to use require.js-style define, with empty dependencies, with a expression", function(done) {
define([], ok);
function ok() { done() };
});
it("should be able to use require.js-style define, with empty dependencies, with a expression and name", function(done) {
define("name", [], done);
});
it("should be able to use require.js-style define, without dependencies", function(done) {
true && define("name", function() {
done();
});
});
it("should be able to use require.js-style define, without dependencies, with a expression", function(done) {
true && define("name", ok);
function ok() { done() };
});
var obj = {};
it("should be able to use require.js-style define, with an object", function() {
module.exports = null;
true && define("blaaa", obj);
expect(module.exports).toBe(obj);
module.exports = null;
define("blaaa", obj);
expect(module.exports).toBe(obj);
module.exports = null;
});
it("should offer AMD-style define for CommonJs", function(done) {
var _test_exports = exports;
var _test_module = module;
define(function(require, exports, module) {
expect((typeof require)).toBe("function");
expect(exports).toBe(_test_exports);
expect(module).toBe(_test_module);
expect(require("./circular")).toBe(1);
done();
});
});
it("should not crash on require.js require only with array", function() {
require(["./circular"]);
});
it("should be able to use AMD require without function expression (empty array)", function(done) {
require([], ok);
function ok() { done() };
});
it("should be able to use AMD require without function expression", function(done) {
require(["./circular"], fn);
function fn(c) {
expect(c).toBe(1);
done();
}
});
it("should create a chunk for require.js require", function(done) {
var sameTick = true;
require(["./c"], function(c) {
expect(sameTick).toBe(false);
expect(c).toBe("c");
expect(require("./d")).toBe("d");
done();
});
sameTick = false;
});
it("should not fail #138", function(done) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory); // AMD
} else if (typeof exports === 'object') {
module.exports = factory(); // Node
} else {
factory(); // Browser global
}
}(function () { done() }));
});
it("should parse a bound function expression 1", function(done) {
define(function(a, require, exports, module) {
expect(a).toBe(123);
expect((typeof require)).toBe("function");
expect(require("./a")).toBe("a");
done();
}.bind(null, 123));
});
it("should parse a bound function expression 2", function(done) {
define("name", function(a, require, exports, module) {
expect(a).toBe(123);
expect((typeof require)).toBe("function");
expect(require("./a")).toBe("a");
done();
}.bind(null, 123));
});
it("should parse a bound function expression 3", function(done) {
define(["./a"], function(number, a) {
expect(number).toBe(123);
expect(a).toBe("a");
done();
}.bind(null, 123));
});
it("should parse a bound function expression 4", function(done) {
define("name", ["./a"], function(number, a) {
expect(number).toBe(123);
expect(a).toBe("a");
done();
}.bind(null, 123));
});
it("should not fail issue #138 second", function() {
(function(define, global) { 'use strict';
define(function (require) {
expect((typeof require)).toBe("function");
expect(require("./a")).toBe("a");
return "#138 2.";
});
})(typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); }, this);
expect(module.exports).toBe("#138 2.");
});
it("should parse an define with empty array and object", function() {
var obj = {ok: 95476};
define([], obj);
expect(module.exports).toBe(obj);
});
it("should parse an define with object", function() {
var obj = {ok: 76243};
define(obj);
expect(module.exports).toBe(obj);
});