@intlify/bundle-utils 2.1.0 → 2.2.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/CHANGELOG.md +9 -0
- package/lib/codegen.d.ts +1 -0
- package/lib/json.d.ts +1 -1
- package/lib/json.js +14 -9
- package/lib/yaml.d.ts +1 -1
- package/lib/yaml.js +14 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
## @intlify/bundle-utils@2.2.0 (2021-12-16)
|
|
3
|
+
|
|
4
|
+
#### :zap: Improvement Features
|
|
5
|
+
* [#75](https://github.com/intlify/bundle-tools/pull/75) Add vue-class-components support via loader option ([@SniperJoe](https://github.com/SniperJoe))
|
|
6
|
+
|
|
7
|
+
#### Committers: 1
|
|
8
|
+
- [@SniperJoe](https://github.com/SniperJoe)
|
|
9
|
+
|
|
10
|
+
|
|
2
11
|
## @intlify/bundle-utils@2.1.0 (2021-11-10)
|
|
3
12
|
|
|
4
13
|
#### :zap: Improvement Features
|
package/lib/codegen.d.ts
CHANGED
package/lib/json.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ import type { CodeGenOptions, CodeGenResult } from './codegen';
|
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export declare function generate(targetSource: string | Buffer, { type, bridge, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
|
|
10
|
+
export declare function generate(targetSource: string | Buffer, { type, bridge, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, useClassComponent }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
|
package/lib/json.js
CHANGED
|
@@ -10,7 +10,7 @@ const codegen_1 = require("./codegen");
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
function generate(targetSource, { type = 'plain', bridge = false, filename = 'vue-i18n-loader.json', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false }, injector) {
|
|
13
|
+
function generate(targetSource, { type = 'plain', bridge = false, filename = 'vue-i18n-loader.json', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false, useClassComponent = false }, injector) {
|
|
14
14
|
const target = Buffer.isBuffer(targetSource)
|
|
15
15
|
? targetSource.toString()
|
|
16
16
|
: targetSource;
|
|
@@ -28,7 +28,8 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
|
|
|
28
28
|
inSourceMap,
|
|
29
29
|
env,
|
|
30
30
|
filename,
|
|
31
|
-
forceStringify
|
|
31
|
+
forceStringify,
|
|
32
|
+
useClassComponent
|
|
32
33
|
};
|
|
33
34
|
const generator = codegen_1.createCodeGenerator(options);
|
|
34
35
|
const ast = jsonc_eslint_parser_1.parseJSON(value, { filePath: filename });
|
|
@@ -56,8 +57,12 @@ function generateNode(generator, node, options, injector) {
|
|
|
56
57
|
const itemsCountStack = [];
|
|
57
58
|
const { forceStringify } = generator.context();
|
|
58
59
|
const codeMaps = new Map();
|
|
59
|
-
const { type, bridge, sourceMap, isGlobal, locale } = options;
|
|
60
|
-
const componentNamespace = bridge
|
|
60
|
+
const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
|
|
61
|
+
const componentNamespace = bridge
|
|
62
|
+
? `Component.options`
|
|
63
|
+
: useClassComponent
|
|
64
|
+
? `Component.__o`
|
|
65
|
+
: `Component`;
|
|
61
66
|
jsonc_eslint_parser_1.traverseNodes(node, {
|
|
62
67
|
enterNode(node, parent) {
|
|
63
68
|
switch (node.type) {
|
|
@@ -72,8 +77,8 @@ function generateNode(generator, node, options, injector) {
|
|
|
72
77
|
const exportSyntax = bridge ? `module.exports =` : `export default`;
|
|
73
78
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
74
79
|
generator.indent();
|
|
75
|
-
generator.pushline(`${componentNamespace}
|
|
76
|
-
generator.push(`${componentNamespace}
|
|
80
|
+
generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
|
|
81
|
+
generator.push(`${componentNamespace}.${variableName}.push({`);
|
|
77
82
|
generator.indent();
|
|
78
83
|
generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
|
|
79
84
|
generator.push(`"resource": `);
|
|
@@ -165,9 +170,9 @@ function generateNode(generator, node, options, injector) {
|
|
|
165
170
|
generator.push(`})`);
|
|
166
171
|
if (bridge && injector) {
|
|
167
172
|
generator.newline();
|
|
168
|
-
generator.pushline(`${componentNamespace}__i18nBridge = ${componentNamespace}__i18nBridge || []`);
|
|
169
|
-
generator.pushline(`${componentNamespace}__i18nBridge.push('${injector()}')`);
|
|
170
|
-
generator.pushline(`delete ${componentNamespace}_Ctor`);
|
|
173
|
+
generator.pushline(`${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`);
|
|
174
|
+
generator.pushline(`${componentNamespace}.__i18nBridge.push('${injector()}')`);
|
|
175
|
+
generator.pushline(`delete ${componentNamespace}._Ctor`);
|
|
171
176
|
}
|
|
172
177
|
generator.deindent();
|
|
173
178
|
generator.pushline(`}`);
|
package/lib/yaml.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ import type { CodeGenOptions, CodeGenResult } from './codegen';
|
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export declare function generate(targetSource: string | Buffer, { type, bridge, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
|
|
10
|
+
export declare function generate(targetSource: string | Buffer, { type, bridge, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
|
package/lib/yaml.js
CHANGED
|
@@ -10,7 +10,7 @@ const yaml_eslint_parser_1 = require("yaml-eslint-parser");
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
function generate(targetSource, { type = 'plain', bridge = false, filename = 'vue-i18n-loader.yaml', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false }, injector) {
|
|
13
|
+
function generate(targetSource, { type = 'plain', bridge = false, useClassComponent = false, filename = 'vue-i18n-loader.yaml', inSourceMap = undefined, locale = '', isGlobal = false, sourceMap = false, env = 'development', forceStringify = false }, injector) {
|
|
14
14
|
const value = Buffer.isBuffer(targetSource)
|
|
15
15
|
? targetSource.toString()
|
|
16
16
|
: targetSource;
|
|
@@ -24,7 +24,8 @@ function generate(targetSource, { type = 'plain', bridge = false, filename = 'vu
|
|
|
24
24
|
inSourceMap,
|
|
25
25
|
env,
|
|
26
26
|
filename,
|
|
27
|
-
forceStringify
|
|
27
|
+
forceStringify,
|
|
28
|
+
useClassComponent
|
|
28
29
|
};
|
|
29
30
|
const generator = codegen_1.createCodeGenerator(options);
|
|
30
31
|
const ast = yaml_eslint_parser_1.parseYAML(value, { filePath: filename });
|
|
@@ -46,8 +47,12 @@ function generateNode(generator, node, options, injector) {
|
|
|
46
47
|
const itemsCountStack = [];
|
|
47
48
|
const { forceStringify } = generator.context();
|
|
48
49
|
const codeMaps = new Map();
|
|
49
|
-
const { type, bridge, sourceMap, isGlobal, locale } = options;
|
|
50
|
-
const componentNamespace = bridge
|
|
50
|
+
const { type, bridge, sourceMap, isGlobal, locale, useClassComponent } = options;
|
|
51
|
+
const componentNamespace = bridge
|
|
52
|
+
? `Component.options`
|
|
53
|
+
: useClassComponent
|
|
54
|
+
? `Component.__o`
|
|
55
|
+
: `Component`;
|
|
51
56
|
yaml_eslint_parser_1.traverseNodes(node, {
|
|
52
57
|
enterNode(node, parent) {
|
|
53
58
|
switch (node.type) {
|
|
@@ -61,8 +66,8 @@ function generateNode(generator, node, options, injector) {
|
|
|
61
66
|
const exportSyntax = bridge ? `module.exports =` : `export default`;
|
|
62
67
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
63
68
|
generator.indent();
|
|
64
|
-
generator.pushline(`${componentNamespace}
|
|
65
|
-
generator.push(`${componentNamespace}
|
|
69
|
+
generator.pushline(`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`);
|
|
70
|
+
generator.push(`${componentNamespace}.${variableName}.push({`);
|
|
66
71
|
generator.indent();
|
|
67
72
|
generator.pushline(`"locale": ${JSON.stringify(localeName)},`);
|
|
68
73
|
generator.push(`"resource": `);
|
|
@@ -156,9 +161,9 @@ function generateNode(generator, node, options, injector) {
|
|
|
156
161
|
generator.push(`})`);
|
|
157
162
|
if (bridge && injector) {
|
|
158
163
|
generator.newline();
|
|
159
|
-
generator.pushline(`${componentNamespace}__i18nBridge = ${componentNamespace}__i18nBridge || []`);
|
|
160
|
-
generator.pushline(`${componentNamespace}__i18nBridge.push('${injector()}')`);
|
|
161
|
-
generator.pushline(`delete ${componentNamespace}_Ctor`);
|
|
164
|
+
generator.pushline(`${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`);
|
|
165
|
+
generator.pushline(`${componentNamespace}.__i18nBridge.push('${injector()}')`);
|
|
166
|
+
generator.pushline(`delete ${componentNamespace}._Ctor`);
|
|
162
167
|
}
|
|
163
168
|
generator.deindent();
|
|
164
169
|
generator.push(`}`);
|