efront 2.43.5 → 3.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coms/basic/parseURL.js +2 -2
- package/coms/basic/parseURL_test.js +32 -0
- package/coms/compile/required.js +15 -7
- package/package.json +1 -1
- package/public/efront.js +1 -1
- package/.editorconfig +0 -5
- package/apps/efront/parse_test.js +0 -1
package/coms/basic/parseURL.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
var reg = /^([
|
|
1
|
+
// -------/// ---------------1-------------//////////////2---3--------//////// ----4----2/////5-----------------------6------------------------//////////////-7--5///8----9----//10--11---10///--12-----8//
|
|
2
|
+
var reg = /^([^\:\/\?#]+\:(?![^\:\/\?\#]*@))?(?:\/\/)?(?:(([^\:\/\?#]+)?(?:\:([^\/\?#]+))?)@)?(([^\/@\:\?\#]*(?:[^\d\@\:\/\?#]|\.)[^\/@\:\?\#]*)?(?:(?:\:|^)(\d+))?)((\/[^\?#]*)?(\?([^#]*))?(#[\s\S]*)?)$/;
|
|
3
3
|
function parseURL(url) {
|
|
4
4
|
if (url === undefined || url === null) url = '';
|
|
5
5
|
var [__, protocol, auth, username, password, host, hostname, port, path, pathname, search, query, hash] = reg.exec(url);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var parseURL = require("./parseURL");
|
|
2
|
+
require("../efront/console");
|
|
3
|
+
var test = function (url, key, value) {
|
|
4
|
+
var parsed = parseURL(url);
|
|
5
|
+
if (parsed[key] !== value) console.log(parsed), console.fail(`url:${url}, key:${key}, expect:${value}, result:${parsed[key]}`);
|
|
6
|
+
else console.pass(`url:${url}, key:${key}, expect:${value}, result:${parsed[key]}`);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
test('http://efront.cc/kugou', 'pathname', '/kugou')
|
|
10
|
+
test('http://efront.cc/kugou?a', 'path', '/kugou?a')
|
|
11
|
+
test('http://yunxu1019@live.cn@github.com/?a', 'username', 'yunxu1019@live.cn')
|
|
12
|
+
test('localhost', 'host', 'localhost')
|
|
13
|
+
test('localhost:80', 'port', '80')
|
|
14
|
+
test('localhost:80/', 'port', '80')
|
|
15
|
+
test(':80', 'port', '80')
|
|
16
|
+
test('80', 'port', '80')
|
|
17
|
+
test('/80', 'pathname', '/80')
|
|
18
|
+
test('a80', 'host', 'a80')
|
|
19
|
+
test('a:80', 'host', 'a:80')
|
|
20
|
+
test('a:b:80', 'host', 'b:80')
|
|
21
|
+
test('a:b@a80', 'auth', 'a:b')
|
|
22
|
+
test('c:a:b@a80', 'auth', 'a:b')
|
|
23
|
+
test('c:d:a:b@a80', 'password', 'a:b')
|
|
24
|
+
test('localhost:', 'protocol', 'localhost:')
|
|
25
|
+
test('localhost:80', 'hostname', 'localhost')
|
|
26
|
+
test('http//:80', 'hostname', 'http')
|
|
27
|
+
test('http//:80', 'pathname', '//:80')
|
|
28
|
+
test('//h:80', 'host', 'h:80')
|
|
29
|
+
test('?80', 'path', '?80')
|
|
30
|
+
test('?80', 'search', '?80')
|
|
31
|
+
test('?80', 'query', '80')
|
|
32
|
+
test('#?80', 'hash', '#?80')
|
package/coms/compile/required.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var getVariables = require("../compile/variables");
|
|
2
|
+
var scanner2 = require("../compile/scanner2");
|
|
3
|
+
var strings = require("../basic/strings");
|
|
5
4
|
function getRequired(data) {
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var require =
|
|
9
|
-
|
|
5
|
+
var code = scanner2(data);
|
|
6
|
+
var { used, envs } = code;
|
|
7
|
+
if (envs.require) var require = used.require;
|
|
8
|
+
if (require instanceof Array) require.map(r => {
|
|
9
|
+
if (r.next && r.next.type === code.SCOPED) {
|
|
10
|
+
var s = r.next;
|
|
11
|
+
var f = s.first;
|
|
12
|
+
if (f && f.type === code.QUOTED && !f.length && /^[`'"]/.test(f.text)) {
|
|
13
|
+
return strings.decode(f.text);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
else require = [];
|
|
10
18
|
return require;
|
|
11
19
|
}
|
|
12
20
|
module.exports = getRequired;
|