more tests, loader fixes

This commit is contained in:
guybedford 2013-08-20 14:33:30 +02:00
parent 87f480c6cb
commit ef2fa2ae57
6 changed files with 167 additions and 29 deletions

View File

@ -37,7 +37,7 @@
var moduleRegEx = /^\s*module\s+("[^"]+"|'[^']+')\s*\{/m;
// AMD and CommonJS regexs for support
var amdDefineRegEx = /^\s*define\s*\(\s*("[^"]+"\s*,|'[^']+'\s*,)?\s*(\[(\s*("[^"]+"|'[^']+')\s*,)*(\s*("[^"]+"|'[^']+'))\])?/m;
var amdDefineRegEx = /^\s*define\s*\(\s*("[^"]+"\s*,|'[^']+'\s*,)?\s*(\[(\s*("[^"]+"|'[^']+')\s*,)*(\s*("[^"]+"|'[^']+')\s*)\])?/m;
var cjsDefineRegEx = /^\s*define\s*\(\s*(function\s*|{|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*\))/m;
var cjsRequireRegEx = /\s*require\s*\(\s*("([^"]+)"|'([^']+)')\s*\)/gm;
var cjsExportsRegEx = /\s*exports\s*\[\s*('[^']+'|"[^"]+")\s*\]|\exports\s*\.\s*[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*|exports\s*\=/m;
@ -45,6 +45,80 @@
// regex to check absolute urls
var absUrlRegEx = /^\/|([^\:\/]*:\/\/)/;
// function to remove the comments from a string
function removeComments(str) {
// output
var curOutIndex = 0,
outString = '';
// mode variables
var singleQuote = false,
doubleQuote = false,
regex = false,
blockComment = false,
lineComment = false;
// character buffer
var lastChar, curChar,
nextChar = str.charAt(0);
for (var i = 0, l = str.length; i < l; i++) {
lastChar = curChar;
curChar = nextChar;
nextChar = str.charAt(i + 1);
if (singleQuote) {
if (curChar === "'" && lastChar !== '\\')
singleQuote = false;
}
else if (doubleQuote) {
if (curChar === '"' && lastChar !== '\\')
doubleQuote = false;
}
else if (regex) {
if (curChar === '/' && lastChar !== '\\')
regex = false;
}
else if (blockComment) {
if (curChar === '/' && lastChar === '*') {
blockComment = false;
curOutIndex = i + 1;
}
}
else if (lineComment) {
if (nextChar === '\n' || nextChar === '\r') {
lineComment = false;
curOutIndex = i + 1;
}
}
else {
doubleQuote = curChar === '"';
singleQuote = curChar === "'";
if (curChar !== '/')
continue;
if (nextChar === '*') {
blockComment = true;
outString += str.substring(curOutIndex, i - 1);
}
else if (nextChar === '/') {
lineComment = true;
outString += str.substring(curOutIndex, i - 1);
}
else {
regex = true;
}
}
}
return outString + str.substr(curOutIndex);
}
// configuration object extension
// objects extend, everything else replaces
var extend = function(objA, objB) {
@ -234,14 +308,6 @@
// do map config
name = applyMap(name, parentName);
// allow for '/' package main referencing
// 'some-package@0.0.1/' -> 'some-package@0.0.1/some-package'
if (name.substr(name.length - 1, 1) == '/') {
var parts = name.indexOf(':') != -1 ? name.substr(name.indexOf(':') + 1).split('/') : name.split('/');
var lastPart = parts[parts.length - 2];
var lastPartName = lastPart.split('@')[0];
name = name + lastPartName;
}
}
if (pluginName)
@ -258,7 +324,7 @@
jspm.config({ depends: sConfig });
}
return name;
},
resolve: function(name, options) {
@ -283,7 +349,7 @@
name = this.baseURL + (this.baseURL.substr(this.baseURL.length - 1, 1) != '/' ? '/' : '') + name;
// js extension
if (!pluginMatch && name.substr(name.length - 3, 3) != '.js')
if (!pluginMatch)
name += '.js';
return name;
@ -328,6 +394,9 @@
if (source.match(importRegEx) || source.match(exportRegEx) || source.match(moduleRegEx))
return;
// remove comments before doing regular expressions
source = removeComments(source);
var match;
// depends config

29
test/test-advanced.html Normal file
View File

@ -0,0 +1,29 @@
<!doctype html>
<html>
<script src="../../es6-module-loader/lib/es6-module-loader.js" type="text/javascript"></script>
<script src="../loader.js" type="text/javascript"></script>
<script>
jspm.config({
map: {
'github:guybedford/jquery@master/bower_components/sizzle/dist/sizzle': 'github:jquery/sizzle@master/sizzle'
}
});
</script>
<script>
jspm.import('test-runner', function(runner) {
runner.execute([
{
name: 'Load jQuery from source',
run: function(complete) {
jspm.import('github:guybedford/jquery@master/src/jquery', complete);
},
confirm: function($) {
if (!$.fn)
return 'jQuery not defined'
}
}
]);
});
</script>

17
test/test-dynamic1.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://jspm.io/loader.js"></script>
<script>
jspm.import('npm:spinning', function(Spinning) {
var spinner = Spinning().text('loading...').light().size(200);
setTimeout(function () {
spinner.remove();
}, 3000);
});
</script>
</head>
<body>
</body>
</html>

5
test/test-dynamic2.html Normal file
View File

@ -0,0 +1,5 @@
<!doctype html>
<script src="https://jspm.io/loader.js"></script>
<script>
jspm.import('github:guybedford/requirebin-shader/shader');
</script>

26
test/test-dynamic3.html Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<script src="https://jspm.io/loader.js"></script>
<script>
jspm.config({
locations: {
kickstrap: 'https://github.jspm.io/guybedford/kickstrap-proto@master'
}
});
jspm.import(['jspm:jquery', 'kickstrap:select2'], function($) {
document.body.className = '';
$('#e1').select2();
});
</script>
<style>
body.hidden {
display: none;
}
</style>
<body class='hidden'>
<select id="e1">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
</select>
</body>

View File

@ -102,23 +102,6 @@
return 'Mapped module not loaded';
}
},
{
name: 'Package shorthand',
run: function(complete) {
jspm.config({
map: {
'myapp': 'tests/my-app'
}
});
jspm.import(['myapp/', 'myapp/sub'], complete)
},
confirm: function(m1, m2) {
if (!m1.package)
return 'Package not loaded';
if (!m2.package)
return 'Package subpath not loaded';
}
},
{
name: 'Package map configuration',
run: function(complete) {
@ -129,7 +112,7 @@
}
}
});
jspm.import(['myapp/map-test'], complete);
jspm.import(['tests/my-app/map-test'], complete);
},
confirm: function(m) {
if (!m.mapDep)
@ -233,6 +216,15 @@
confirm: function(m) {
}
},
{
name: 'Font plugin',
run: function(complete) {
jspm.import('#google Port Lligat Slab, Droid Sans !font', complete);
},
confirm: function(m) {
}
},
{
name: 'onLoad hook',
run: function(complete) {