@yozora/tokenizer-ecma-import 2.0.0-alpha.2 → 2.0.1
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/lib/cjs/index.js +7 -5
- package/lib/esm/index.js +8 -6
- package/lib/types/types.d.ts +3 -3
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -8,11 +8,13 @@ var coreTokenizer = require('@yozora/core-tokenizer');
|
|
|
8
8
|
|
|
9
9
|
const namedImportItemRegex = /^(\w+)(?:\s+as\s+(\w+))?$/;
|
|
10
10
|
const namedImportRegex = /\{\s*((?:[\w]+(?:\s+as\s+[\w]+)?\s*,\s*)*[\w]+(?:\s+as\s+[\w]+)?)\s*\}\s*/;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const endRegex = /\s*;*\s*$/;
|
|
12
|
+
const regex1 = new RegExp(/^import\s+(['"])([^'"]+)\1/.source + endRegex.source);
|
|
13
|
+
const regex2 = new RegExp(/^import\s+([\w]+)\s+from\s+(['"])([^'"]+)\2/.source + endRegex.source);
|
|
13
14
|
const regex3 = new RegExp(/^import\s+(?:([\w]+)\s*,\s*)?/.source +
|
|
14
15
|
namedImportRegex.source +
|
|
15
|
-
/from\s+(['"])([^'"]+)\3
|
|
16
|
+
/from\s+(['"])([^'"]+)\3/.source +
|
|
17
|
+
endRegex.source);
|
|
16
18
|
function resolveNameImports(text) {
|
|
17
19
|
const items = text.split(/\s*,\s*/g).filter(item => item.length > 0);
|
|
18
20
|
const result = [];
|
|
@@ -52,8 +54,8 @@ const match = function () {
|
|
|
52
54
|
let m;
|
|
53
55
|
let token = null;
|
|
54
56
|
const position = () => ({
|
|
55
|
-
start: coreTokenizer.
|
|
56
|
-
end: coreTokenizer.
|
|
57
|
+
start: coreTokenizer.calcStartPoint(nodePoints, startIndex),
|
|
58
|
+
end: coreTokenizer.calcEndPoint(nodePoints, endIndex - 1),
|
|
57
59
|
});
|
|
58
60
|
if ((m = regex1.exec(text)) != null) {
|
|
59
61
|
token = {
|
package/lib/esm/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { EcmaImportType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, calcTrimBoundaryOfCodePoints, calcStringFromNodePoints } from '@yozora/character';
|
|
3
|
-
import {
|
|
3
|
+
import { calcStartPoint, calcEndPoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
5
|
const namedImportItemRegex = /^(\w+)(?:\s+as\s+(\w+))?$/;
|
|
6
6
|
const namedImportRegex = /\{\s*((?:[\w]+(?:\s+as\s+[\w]+)?\s*,\s*)*[\w]+(?:\s+as\s+[\w]+)?)\s*\}\s*/;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const endRegex = /\s*;*\s*$/;
|
|
8
|
+
const regex1 = new RegExp(/^import\s+(['"])([^'"]+)\1/.source + endRegex.source);
|
|
9
|
+
const regex2 = new RegExp(/^import\s+([\w]+)\s+from\s+(['"])([^'"]+)\2/.source + endRegex.source);
|
|
9
10
|
const regex3 = new RegExp(/^import\s+(?:([\w]+)\s*,\s*)?/.source +
|
|
10
11
|
namedImportRegex.source +
|
|
11
|
-
/from\s+(['"])([^'"]+)\3
|
|
12
|
+
/from\s+(['"])([^'"]+)\3/.source +
|
|
13
|
+
endRegex.source);
|
|
12
14
|
function resolveNameImports(text) {
|
|
13
15
|
const items = text.split(/\s*,\s*/g).filter(item => item.length > 0);
|
|
14
16
|
const result = [];
|
|
@@ -48,8 +50,8 @@ const match = function () {
|
|
|
48
50
|
let m;
|
|
49
51
|
let token = null;
|
|
50
52
|
const position = () => ({
|
|
51
|
-
start:
|
|
52
|
-
end:
|
|
53
|
+
start: calcStartPoint(nodePoints, startIndex),
|
|
54
|
+
end: calcEndPoint(nodePoints, endIndex - 1),
|
|
53
55
|
});
|
|
54
56
|
if ((m = regex1.exec(text)) != null) {
|
|
55
57
|
token = {
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EcmaImport, EcmaImportType } from '@yozora/ast';
|
|
2
2
|
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = EcmaImportType;
|
|
4
|
-
export declare type INode =
|
|
4
|
+
export declare type INode = EcmaImport;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-ecma-import";
|
|
6
|
-
export declare type IToken = IPartialYastBlockToken<T> & Omit<
|
|
6
|
+
export declare type IToken = IPartialYastBlockToken<T> & Omit<EcmaImport, 'type'>;
|
|
7
7
|
export declare type IThis = ITokenizer;
|
|
8
8
|
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-ecma-import",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@yozora/ast": "^2.0.
|
|
39
|
-
"@yozora/character": "^2.0.
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.
|
|
38
|
+
"@yozora/ast": "^2.0.1",
|
|
39
|
+
"@yozora/character": "^2.0.1",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.1"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3aea33091e402bd6c7754d91d549e8d648475073"
|
|
43
43
|
}
|