@intlify/bundle-utils 2.1.0 → 2.2.2

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 CHANGED
@@ -1,4 +1,40 @@
1
1
 
2
+ ## @intlify/bundle-utils@2.2.2 (2022-04-05)
3
+
4
+ #### :zap: Improvement Features
5
+ * [#100](https://github.com/intlify/bundle-tools/pull/100) fix(bundle-utils): pinned latest stable version ([@kazupon](https://github.com/kazupon))
6
+
7
+ #### Committers: 1
8
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
9
+
10
+
11
+ ## @intlify/bundle-utils@2.2.1 (2022-03-22)
12
+
13
+ #### :bug: Bug Fixes
14
+ * [#98](https://github.com/intlify/bundle-tools/pull/98) fix(bundle-utils): fix nested array code generation ([@kazupon](https://github.com/kazupon))
15
+
16
+ #### Committers: 1
17
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
18
+
19
+
20
+ ## @intlify/bundle-utils@2.2.1 (2022-03-22)
21
+
22
+ #### :bug: Bug Fixes
23
+ * [#98](https://github.com/intlify/bundle-tools/pull/98) fix(bundle-utils): fix nested array code generation ([@kazupon](https://github.com/kazupon))
24
+
25
+ #### Committers: 1
26
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
27
+
28
+
29
+ ## @intlify/bundle-utils@2.2.0 (2021-12-16)
30
+
31
+ #### :zap: Improvement Features
32
+ * [#75](https://github.com/intlify/bundle-tools/pull/75) Add vue-class-components support via loader option ([@SniperJoe](https://github.com/SniperJoe))
33
+
34
+ #### Committers: 1
35
+ - [@SniperJoe](https://github.com/SniperJoe)
36
+
37
+
2
38
  ## @intlify/bundle-utils@2.1.0 (2021-11-10)
3
39
 
4
40
  #### :zap: Improvement Features
package/lib/codegen.d.ts CHANGED
@@ -32,6 +32,7 @@ export interface CodeGenOptions {
32
32
  locale?: string;
33
33
  env?: DevEnv;
34
34
  forceStringify?: boolean;
35
+ useClassComponent?: boolean;
35
36
  onWarn?: (msg: string) => void;
36
37
  onError?: (msg: string) => void;
37
38
  }
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 ? `Component.options.` : `Component.`;
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}${variableName} = ${componentNamespace}${variableName} || []`);
76
- generator.push(`${componentNamespace}${variableName}.push({`);
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(`}`);
@@ -196,12 +201,20 @@ function generateNode(generator, node, options, injector) {
196
201
  }
197
202
  generator.deindent();
198
203
  generator.push(`]`);
204
+ if (parent.type === 'JSONArrayExpression') {
205
+ if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
206
+ generator.pushline(`,`);
207
+ }
208
+ }
199
209
  break;
200
210
  case 'JSONLiteral':
201
211
  if (parent.type === 'JSONArrayExpression') {
202
212
  if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
203
213
  generator.pushline(`,`);
204
214
  }
215
+ else {
216
+ generator.pushline(`,`);
217
+ }
205
218
  }
206
219
  break;
207
220
  default:
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 ? `Component.options.` : `Component.`;
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}${variableName} = ${componentNamespace}${variableName} || []`);
65
- generator.push(`${componentNamespace}${variableName}.push({`);
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(`}`);
@@ -187,12 +192,20 @@ function generateNode(generator, node, options, injector) {
187
192
  }
188
193
  generator.deindent();
189
194
  generator.push(`]`);
195
+ if (parent.type === 'YAMLSequence') {
196
+ if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
197
+ generator.pushline(`,`);
198
+ }
199
+ }
190
200
  break;
191
201
  case 'YAMLScalar':
192
202
  if (parent.type === 'YAMLSequence') {
193
203
  if (itemsCountStack[itemsCountStack.length - 1] !== 0) {
194
204
  generator.pushline(`,`);
195
205
  }
206
+ else {
207
+ generator.pushline(`,`);
208
+ }
196
209
  }
197
210
  break;
198
211
  default:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intlify/bundle-utils",
3
3
  "description": "Bundle utilities for Intlify project",
4
- "version": "2.1.0",
4
+ "version": "2.2.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -19,8 +19,8 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@intlify/message-compiler": "beta",
23
- "@intlify/shared": "beta",
22
+ "@intlify/message-compiler": "^9.1.0",
23
+ "@intlify/shared": "^9.1.0",
24
24
  "jsonc-eslint-parser": "^1.0.1",
25
25
  "source-map": "^0.6.1",
26
26
  "yaml-eslint-parser": "^0.3.2"