@yozora/tokenizer-ecma-import 1.2.0 → 2.0.0-alpha.0
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 +37 -24
- package/lib/esm/index.js +36 -25
- package/lib/types/index.d.ts +4 -4
- package/lib/types/match.d.ts +15 -0
- package/lib/types/parse.d.ts +3 -0
- package/lib/types/tokenizer.d.ts +6 -25
- package/lib/types/types.d.ts +6 -5
- package/lib/types/util.d.ts +2 -2
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -6,8 +6,6 @@ var ast = require('@yozora/ast');
|
|
|
6
6
|
var character = require('@yozora/character');
|
|
7
7
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
8
|
|
|
9
|
-
const uniqueName = '@yozora/tokenizer-ecma-import';
|
|
10
|
-
|
|
11
9
|
const namedImportItemRegex = /^(\w+)(?:\s+as\s+(\w+))?$/;
|
|
12
10
|
const namedImportRegex = /\{\s*((?:[\w]+(?:\s+as\s+[\w]+)?\s*,\s*)*[\w]+(?:\s+as\s+[\w]+)?)\s*\}\s*/;
|
|
13
11
|
const regex1 = /^import\s+(['"])([^'"]+)\1$/;
|
|
@@ -25,16 +23,12 @@ function resolveNameImports(text) {
|
|
|
25
23
|
return result;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
this.isContainingBlock = false;
|
|
36
|
-
}
|
|
37
|
-
eatOpener(line) {
|
|
26
|
+
const match = function () {
|
|
27
|
+
return {
|
|
28
|
+
isContainingBlock: false,
|
|
29
|
+
eatOpener,
|
|
30
|
+
};
|
|
31
|
+
function eatOpener(line) {
|
|
38
32
|
if (line.countOfPrecedeSpaces >= 4)
|
|
39
33
|
return null;
|
|
40
34
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
@@ -88,21 +82,40 @@ class EcmaImportTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
|
88
82
|
namedImports: resolveNameImports(m[2]),
|
|
89
83
|
};
|
|
90
84
|
}
|
|
91
|
-
return token === null
|
|
92
|
-
? null
|
|
93
|
-
: { token, nextIndex: endIndex, saturated: true };
|
|
85
|
+
return token === null ? null : { token, nextIndex: endIndex, saturated: true };
|
|
94
86
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const parse = function () {
|
|
90
|
+
return {
|
|
91
|
+
parse: token => {
|
|
92
|
+
const node = {
|
|
93
|
+
type: ast.EcmaImportType,
|
|
94
|
+
moduleName: token.moduleName,
|
|
95
|
+
defaultImport: token.defaultImport,
|
|
96
|
+
namedImports: token.namedImports,
|
|
97
|
+
};
|
|
98
|
+
return node;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const uniqueName = '@yozora/tokenizer-ecma-import';
|
|
104
|
+
|
|
105
|
+
class EcmaImportTokenizer extends coreTokenizer.BaseBlockTokenizer {
|
|
106
|
+
constructor(props = {}) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
super({
|
|
109
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
110
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.ATOMIC,
|
|
111
|
+
});
|
|
112
|
+
this.match = match;
|
|
113
|
+
this.parse = parse;
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
exports.EcmaImportTokenizer = EcmaImportTokenizer;
|
|
107
118
|
exports.EcmaImportTokenizerName = uniqueName;
|
|
108
|
-
exports[
|
|
119
|
+
exports["default"] = EcmaImportTokenizer;
|
|
120
|
+
exports.ecmaImportMatch = match;
|
|
121
|
+
exports.ecmaImportParse = parse;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { EcmaImportType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, calcTrimBoundaryOfCodePoints, calcStringFromNodePoints } from '@yozora/character';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const uniqueName = '@yozora/tokenizer-ecma-import';
|
|
3
|
+
import { calcStartYastNodePoint, calcEndYastNodePoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
6
4
|
|
|
7
5
|
const namedImportItemRegex = /^(\w+)(?:\s+as\s+(\w+))?$/;
|
|
8
6
|
const namedImportRegex = /\{\s*((?:[\w]+(?:\s+as\s+[\w]+)?\s*,\s*)*[\w]+(?:\s+as\s+[\w]+)?)\s*\}\s*/;
|
|
@@ -21,16 +19,12 @@ function resolveNameImports(text) {
|
|
|
21
19
|
return result;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
this.isContainingBlock = false;
|
|
32
|
-
}
|
|
33
|
-
eatOpener(line) {
|
|
22
|
+
const match = function () {
|
|
23
|
+
return {
|
|
24
|
+
isContainingBlock: false,
|
|
25
|
+
eatOpener,
|
|
26
|
+
};
|
|
27
|
+
function eatOpener(line) {
|
|
34
28
|
if (line.countOfPrecedeSpaces >= 4)
|
|
35
29
|
return null;
|
|
36
30
|
const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
|
|
@@ -84,19 +78,36 @@ class EcmaImportTokenizer extends BaseBlockTokenizer {
|
|
|
84
78
|
namedImports: resolveNameImports(m[2]),
|
|
85
79
|
};
|
|
86
80
|
}
|
|
87
|
-
return token === null
|
|
88
|
-
? null
|
|
89
|
-
: { token, nextIndex: endIndex, saturated: true };
|
|
81
|
+
return token === null ? null : { token, nextIndex: endIndex, saturated: true };
|
|
90
82
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const parse = function () {
|
|
86
|
+
return {
|
|
87
|
+
parse: token => {
|
|
88
|
+
const node = {
|
|
89
|
+
type: EcmaImportType,
|
|
90
|
+
moduleName: token.moduleName,
|
|
91
|
+
defaultImport: token.defaultImport,
|
|
92
|
+
namedImports: token.namedImports,
|
|
93
|
+
};
|
|
94
|
+
return node;
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const uniqueName = '@yozora/tokenizer-ecma-import';
|
|
100
|
+
|
|
101
|
+
class EcmaImportTokenizer extends BaseBlockTokenizer {
|
|
102
|
+
constructor(props = {}) {
|
|
103
|
+
var _a, _b;
|
|
104
|
+
super({
|
|
105
|
+
name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
|
|
106
|
+
priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.ATOMIC,
|
|
107
|
+
});
|
|
108
|
+
this.match = match;
|
|
109
|
+
this.parse = parse;
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
export { EcmaImportTokenizer, uniqueName as EcmaImportTokenizerName, EcmaImportTokenizer as default };
|
|
113
|
+
export { EcmaImportTokenizer, uniqueName as EcmaImportTokenizerName, EcmaImportTokenizer as default, match as ecmaImportMatch, parse as ecmaImportParse };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { match as ecmaImportMatch } from './match';
|
|
2
|
+
export { parse as ecmaImportParse } from './parse';
|
|
3
|
+
export { EcmaImportTokenizer, EcmaImportTokenizer as default } from './tokenizer';
|
|
3
4
|
export { uniqueName as EcmaImportTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default EcmaImportTokenizer;
|
|
5
|
+
export type { IHookContext as ecmaImportHookContext, IToken as IEcmaImportToken, ITokenizerProps as IEcmaImportProps, } from './types';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
+
import type { IHookContext, IToken, T } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Examples
|
|
5
|
+
*
|
|
6
|
+
* import '@yozora/parser'
|
|
7
|
+
* import Parser from '@yozora/parser'
|
|
8
|
+
* import Parser, { YozoraParserProps } from '@yozora/parser'
|
|
9
|
+
* import { YozoraParserProps } from '@yozora/parser'
|
|
10
|
+
* import { YozoraParser, YozoraParser as Parser } from '@yozora/parser'
|
|
11
|
+
*
|
|
12
|
+
* @see https://github.com/syntax-tree/mdast#strong
|
|
13
|
+
* @see https://github.github.com/gfm/#emphasis-and-strong-emphasis
|
|
14
|
+
*/
|
|
15
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
3
|
-
import type {
|
|
4
|
-
/**
|
|
5
|
-
* Params for constructing EcmaImportTokenizer
|
|
6
|
-
*/
|
|
7
|
-
export interface EcmaImportTokenizerProps {
|
|
8
|
-
}
|
|
3
|
+
import type { IHookContext, INode, IToken, ITokenizerProps, T } from './types';
|
|
9
4
|
/**
|
|
10
5
|
* Lexical Analyzer for Ecma Import statement
|
|
11
|
-
*
|
|
12
|
-
* Examples
|
|
13
|
-
*
|
|
14
|
-
* import '@yozora/parser'
|
|
15
|
-
* import Parser from '@yozora/parser'
|
|
16
|
-
* import Parser, { YozoraParserProps } from '@yozora/parser'
|
|
17
|
-
* import { YozoraParserProps } from '@yozora/parser'
|
|
18
|
-
* import { YozoraParser, YozoraParser as Parser } from '@yozora/parser'
|
|
19
|
-
*
|
|
20
6
|
* @see https://github.com/syntax-tree/mdast#strong
|
|
21
7
|
* @see https://github.github.com/gfm/#emphasis-and-strong-emphasis
|
|
22
8
|
*/
|
|
23
|
-
export declare class EcmaImportTokenizer extends BaseBlockTokenizer
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @see TokenizerParseBlockHook
|
|
30
|
-
*/
|
|
31
|
-
parseBlock(token: Readonly<Token>): ResultOfParse<T, Node>;
|
|
9
|
+
export declare class EcmaImportTokenizer extends BaseBlockTokenizer<T, IToken, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
|
|
10
|
+
constructor(props?: ITokenizerProps);
|
|
11
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IHookContext>;
|
|
12
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
|
|
32
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { EcmaImportType, IEcmaImport } from '@yozora/ast';
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = EcmaImportType;
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type INode = IEcmaImport;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-ecma-import";
|
|
6
|
-
export declare type
|
|
7
|
-
export declare type
|
|
6
|
+
export declare type IToken = IPartialYastBlockToken<T> & Omit<IEcmaImport, 'type'>;
|
|
7
|
+
export declare type IHookContext = ITokenizer;
|
|
8
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/lib/types/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IEcmaImportNamedImport } from '@yozora/ast';
|
|
2
2
|
/**
|
|
3
3
|
* import '@yozora.parser'
|
|
4
4
|
*/
|
|
@@ -20,4 +20,4 @@ export declare const regex3: RegExp;
|
|
|
20
20
|
*
|
|
21
21
|
* @param text
|
|
22
22
|
*/
|
|
23
|
-
export declare function resolveNameImports(text: string):
|
|
23
|
+
export declare function resolveNameImports(text: string): IEcmaImportNamedImport[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-ecma-import",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
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": "^
|
|
39
|
-
"@yozora/character": "^
|
|
40
|
-
"@yozora/core-tokenizer": "^
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.0",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
43
43
|
}
|