Skip to content

Commit a838655

Browse files
committed
Fixes requirejs#1577, plugin normalize called too many times
1 parent 3e55417 commit a838655

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

require.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ var requirejs, require, define;
440440
//Account for relative paths if there is a base name.
441441
if (name) {
442442
if (prefix) {
443-
if (pluginModule && pluginModule.normalize) {
443+
if (isNormalized) {
444+
normalizedName = name;
445+
} else if (pluginModule && pluginModule.normalize) {
444446
//Plugin is loaded, use its normalize method.
445447
normalizedName = pluginModule.normalize(name, function (name) {
446448
return normalize(name, parentName, applyMap);
@@ -972,7 +974,8 @@ var requirejs, require, define;
972974
//prefix and name should already be normalized, no need
973975
//for applying map config again either.
974976
normalizedMap = makeModuleMap(map.prefix + '!' + name,
975-
this.map.parentMap);
977+
this.map.parentMap,
978+
true);
976979
on(normalizedMap,
977980
'defined', bind(this, function (value) {
978981
this.map.normalizedMap = normalizedMap;

tests/all.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ doh.registerUrl("pluginsSync", "../plugins/sync.html");
140140
doh.registerUrl("pluginsOnError", "../plugins/onerror/onerror.html");
141141
doh.registerUrl("doublePluginCall", "../plugins/double.html");
142142
doh.registerUrl("pluginsNameOnly", "../plugins/nameOnly.html");
143+
doh.registerUrl("pluginNormalize", "../pluginNormalize/pluginNormalize.html");
144+
doh.registerUrl("pluginNormalizeLoad", "../pluginNormalizeLoad/pluginNormalizeLoad.html");
143145
doh.registerUrl("pluginsDelegated", "../plugins/delegated/delegated.html");
144146
doh.registerUrl("pluginsFromText", "../plugins/fromText/fromText.html");
145147
doh.registerUrl("pluginsFromTextEvalError", "../plugins/fromTextEvalError/fromTextEvalError.html");
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>require.js: Remote URL Test</title>
5+
<script type="text/javascript" src="../../require.js"></script>
6+
<script type="text/javascript" src="../doh/runner.js"></script>
7+
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
8+
<script type="text/javascript">
9+
10+
define("Plugin", function() {
11+
return {
12+
load: function(name, parentRequire, onload, config) {
13+
onload(name);
14+
},
15+
normalize: function(name, normalize) {
16+
return name + '.xyz';
17+
}
18+
}
19+
});
20+
21+
require({
22+
baseUrl: "./"
23+
},
24+
["Plugin!hello", "Plugin!world"],
25+
function(hello, world) {
26+
doh.register(
27+
"pluginNormalize",
28+
[
29+
function pluginNormalize(t){
30+
t.is("hello.xyz", hello);
31+
t.is("world.xyz", world);
32+
}
33+
]
34+
);
35+
36+
doh.run();
37+
}
38+
);
39+
40+
41+
</script>
42+
</head>
43+
<body>
44+
<h1>require.js: Plugin Normalize Test</h1>
45+
<p>Check console for messages</p>
46+
</body>
47+
</html>

tests/pluginNormalizeLoad/Plugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
define(function() {
2+
return {
3+
load: function(name, parentRequire, onload, config) {
4+
onload(name);
5+
},
6+
normalize: function(name, normalize) {
7+
return name + '.xyz';
8+
}
9+
}
10+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>require.js: Remote URL Test</title>
5+
<script type="text/javascript" src="../../require.js"></script>
6+
<script type="text/javascript" src="../doh/runner.js"></script>
7+
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
8+
<script type="text/javascript">
9+
require({
10+
baseUrl: "./"
11+
},
12+
["Plugin!hello", "Plugin!world"],
13+
function(hello, world) {
14+
doh.register(
15+
"pluginNormalizeLoad",
16+
[
17+
function pluginNormalizeLoad(t){
18+
t.is("hello.xyz", hello);
19+
t.is("world.xyz", world);
20+
}
21+
]
22+
);
23+
24+
doh.run();
25+
}
26+
);
27+
28+
29+
</script>
30+
</head>
31+
<body>
32+
<h1>require.js: Plugin Normalize Test</h1>
33+
<p>Check console for messages</p>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)