From 708288cee467ae6fa872470b99a49a7c9968963c Mon Sep 17 00:00:00 2001 From: jrburke Date: Sun, 4 Sep 2016 11:26:55 -0700 Subject: [PATCH] Fixes #1552, includes starMap fix and test --- require.js | 24 ++++++++---- tests/all.js | 2 + tests/mapConfig/topLevel/a.js | 6 +++ tests/mapConfig/topLevel/b.js | 3 ++ tests/mapConfig/topLevel/main.js | 3 ++ .../topLevel/mapConfigTopLevel-tests.js | 37 +++++++++++++++++++ .../mapConfig/topLevel/mapConfigTopLevel.html | 18 +++++++++ tests/mapConfig/topLevel/modules/e.js | 3 ++ tests/mapConfig/topLevel/util/func.js | 6 +++ tests/mapConfig/topLevel/vendor/c.js | 3 ++ tests/mapConfig/topLevel/vendor/nested/d.js | 6 +++ 11 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 tests/mapConfig/topLevel/a.js create mode 100644 tests/mapConfig/topLevel/b.js create mode 100644 tests/mapConfig/topLevel/main.js create mode 100644 tests/mapConfig/topLevel/mapConfigTopLevel-tests.js create mode 100644 tests/mapConfig/topLevel/mapConfigTopLevel.html create mode 100644 tests/mapConfig/topLevel/modules/e.js create mode 100644 tests/mapConfig/topLevel/util/func.js create mode 100644 tests/mapConfig/topLevel/vendor/c.js create mode 100644 tests/mapConfig/topLevel/vendor/nested/d.js diff --git a/require.js b/require.js index e659c4577..0b82dcc3f 100644 --- a/require.js +++ b/require.js @@ -268,7 +268,7 @@ var requirejs, require, define; */ function normalize(name, baseName, applyMap) { var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex, - foundMap, foundI, foundStarMap, starI, normalizedBaseParts, + foundMap, foundI, starMapEntry, foundStarMap, starI, normalizedBaseParts, baseParts = (baseName && baseName.split('/')), map = config.map, starMap = map && map['*']; @@ -318,7 +318,7 @@ var requirejs, require, define; //this name. if (mapValue) { mapValue = getOwn(mapValue, nameSegment); - if (mapValue) { + if (typeof mapValue === 'string') { //Match, update name to the new value. foundMap = mapValue; foundI = i; @@ -331,19 +331,27 @@ var requirejs, require, define; //Check for a star map match, but just hold on to it, //if there is a shorter segment match later in a matching //config, then favor over this star map. - if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) { - foundStarMap = getOwn(starMap, nameSegment); - starI = i; + if (!foundStarMap && starMap) { + starMapEntry = getOwn(starMap, nameSegment); + if (typeof starMapEntry === 'string') { + foundStarMap = starMapEntry; + starI = i; + } } } - if (!foundMap && foundStarMap) { + if (typeof foundMap !== 'string' && typeof foundStarMap === 'string') { foundMap = foundStarMap; foundI = starI; } - if (foundMap) { - nameParts.splice(0, foundI, foundMap); + if (typeof foundMap === 'string') { + if (foundMap) { + nameParts.splice(0, foundI, foundMap); + } else { + nameParts.splice(0, foundI); + } + name = nameParts.join('/'); } } diff --git a/tests/all.js b/tests/all.js index 17f32714e..60d7f50c5 100644 --- a/tests/all.js +++ b/tests/all.js @@ -114,6 +114,8 @@ doh.registerUrl("mapConfigRelative", "../mapConfig/mapConfigRelative.html"); doh.registerUrl("mapConfigSpecificity", "../mapConfig/mapConfigSpecificity.html"); doh.registerUrl("mapConfigPlugin", "../mapConfig/mapConfigPlugin.html"); doh.registerUrl("mapConfigPluginBuilt", "../mapConfig/built/mapConfigPluginBuilt.html"); +doh.registerUrl("mapConfigTopLevel", "../mapConfig/topLevel/mapConfigTopLevel.html"); + doh.registerUrl("secondLateConfigPlugin", "../secondLateConfigPlugin/secondLateConfigPlugin.html"); doh.registerUrl("layers", "../layers/layers.html", 10000); diff --git a/tests/mapConfig/topLevel/a.js b/tests/mapConfig/topLevel/a.js new file mode 100644 index 000000000..0370121f7 --- /dev/null +++ b/tests/mapConfig/topLevel/a.js @@ -0,0 +1,6 @@ +define(['another/nested/b', 'vendor/c'], function (b, c) { + return { + b: b, + c: c + }; +}); diff --git a/tests/mapConfig/topLevel/b.js b/tests/mapConfig/topLevel/b.js new file mode 100644 index 000000000..6a0edcdb1 --- /dev/null +++ b/tests/mapConfig/topLevel/b.js @@ -0,0 +1,3 @@ +define({ + name: 'b' +}); diff --git a/tests/mapConfig/topLevel/main.js b/tests/mapConfig/topLevel/main.js new file mode 100644 index 000000000..bf19e00f1 --- /dev/null +++ b/tests/mapConfig/topLevel/main.js @@ -0,0 +1,3 @@ +define(['sub/level/a'], function (a) { + return a; +}); diff --git a/tests/mapConfig/topLevel/mapConfigTopLevel-tests.js b/tests/mapConfig/topLevel/mapConfigTopLevel-tests.js new file mode 100644 index 000000000..14a43a6d2 --- /dev/null +++ b/tests/mapConfig/topLevel/mapConfigTopLevel-tests.js @@ -0,0 +1,37 @@ +/*global doh */ +require({ + baseUrl: './', + map: { + '*': { + //Remove 'sub/level' from + //any module ID, so that the + //rest of the modules ID is + //treated as top level. + 'sub/level': '', + }, + 'vendor/nested': { + 'sub/level': 'modules' + }, + 'a': { + 'another/nested': '' + } + } + }, + ['util/func', 'main'], + function(utilFunc, main) { + 'use strict'; + doh.register( + 'mapConfigTopLevel', + [ + function mapConfigTopLevel(t){ + t.is('util/func', utilFunc.name); + t.is('d', utilFunc.d.name); + t.is('e', utilFunc.d.e.name); + t.is('b', main.b.name); + t.is('c', main.c.name); + } + ] + ); + doh.run(); + } +); diff --git a/tests/mapConfig/topLevel/mapConfigTopLevel.html b/tests/mapConfig/topLevel/mapConfigTopLevel.html new file mode 100644 index 000000000..1132cd7bc --- /dev/null +++ b/tests/mapConfig/topLevel/mapConfigTopLevel.html @@ -0,0 +1,18 @@ + + + + require.js: Map Config Top Level Test + + + + + + +

require.js: Map Config Top Level Test

+

Test using '' in the map config, for indicating a top level module ID + mapping.

+ #1552

+ +

Check console for messages

+ + diff --git a/tests/mapConfig/topLevel/modules/e.js b/tests/mapConfig/topLevel/modules/e.js new file mode 100644 index 000000000..d990dc5e5 --- /dev/null +++ b/tests/mapConfig/topLevel/modules/e.js @@ -0,0 +1,3 @@ +define({ + name: 'e' +}); diff --git a/tests/mapConfig/topLevel/util/func.js b/tests/mapConfig/topLevel/util/func.js new file mode 100644 index 000000000..83ec1cc5e --- /dev/null +++ b/tests/mapConfig/topLevel/util/func.js @@ -0,0 +1,6 @@ +define(['vendor/nested/d'], function(d) { + return { + name: 'util/func', + d: d + }; +}); diff --git a/tests/mapConfig/topLevel/vendor/c.js b/tests/mapConfig/topLevel/vendor/c.js new file mode 100644 index 000000000..f01a0f832 --- /dev/null +++ b/tests/mapConfig/topLevel/vendor/c.js @@ -0,0 +1,3 @@ +define({ + name: 'c' +}); diff --git a/tests/mapConfig/topLevel/vendor/nested/d.js b/tests/mapConfig/topLevel/vendor/nested/d.js new file mode 100644 index 000000000..f65f85fc4 --- /dev/null +++ b/tests/mapConfig/topLevel/vendor/nested/d.js @@ -0,0 +1,6 @@ +define(['sub/level/e'], function(e) { + return { + name: 'd', + e: e + }; +}); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy