@intlify/vue-i18n-extensions 4.0.0 → 5.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/builder.js CHANGED
@@ -12,7 +12,7 @@ const shared_1 = require("@intlify/shared");
12
12
  * @public
13
13
  */
14
14
  function createContentBuilder(options = {}) {
15
- let _indentLevel = options.indentLevel != null && shared_1.isNumber(options.indentLevel)
15
+ let _indentLevel = options.indentLevel != null && (0, shared_1.isNumber)(options.indentLevel)
16
16
  ? options.indentLevel
17
17
  : 0;
18
18
  let _content = '';
package/lib/report.js CHANGED
@@ -4,16 +4,16 @@ exports.report = exports.getReportMessage = void 0;
4
4
  const shared_1 = require("@intlify/shared");
5
5
  // TODO: should be extracted as i18n resources (intlify project self hosting!)
6
6
  const ReportMessages = {
7
- [1 /* UNEXPECTED_DIRECTIVE_EXPRESSION */]: `Unexpected directive expression: {0}`,
8
- [2 /* NOT_SUPPORTED */]: `Not supported transform: {0}`,
9
- [3 /* FAILED_VALUE_EVALUATION */]: `Failed valu evaluation: {0}`,
10
- [4 /* REQUIRED_PARAMETER */]: `Required parameter: {0}`,
11
- [5 /* INVALID_PARAMETER_TYPE */]: `Required parameter: {0}`,
12
- [6 /* NOT_SUPPORTED_PRESERVE */]: `Not supportted 'preserve': {0}`,
13
- [7 /* ORVERRIDE_ELEMENT_CHILDREN */]: `v-t will override element children: {0}`
7
+ [1 /* ReportCodes.UNEXPECTED_DIRECTIVE_EXPRESSION */]: `Unexpected directive expression: {0}`,
8
+ [2 /* ReportCodes.NOT_SUPPORTED */]: `Not supported transform: {0}`,
9
+ [3 /* ReportCodes.FAILED_VALUE_EVALUATION */]: `Failed valu evaluation: {0}`,
10
+ [4 /* ReportCodes.REQUIRED_PARAMETER */]: `Required parameter: {0}`,
11
+ [5 /* ReportCodes.INVALID_PARAMETER_TYPE */]: `Required parameter: {0}`,
12
+ [6 /* ReportCodes.NOT_SUPPORTED_PRESERVE */]: `Not supportted 'preserve': {0}`,
13
+ [7 /* ReportCodes.ORVERRIDE_ELEMENT_CHILDREN */]: `v-t will override element children: {0}`
14
14
  };
15
15
  function getReportMessage(code, ...args) {
16
- return shared_1.format(ReportMessages[code], ...args);
16
+ return (0, shared_1.format)(ReportMessages[code], ...args);
17
17
  }
18
18
  exports.getReportMessage = getReportMessage;
19
19
  function createExtensionsError(code, msg, loc) {
@@ -26,7 +26,7 @@ function createExtensionsError(code, msg, loc) {
26
26
  }
27
27
  function report(code, optinos = {}) {
28
28
  const mode = optinos.mode &&
29
- shared_1.isString(optinos.mode) &&
29
+ (0, shared_1.isString)(optinos.mode) &&
30
30
  ['warn', 'error'].includes(optinos.mode)
31
31
  ? optinos.mode
32
32
  : 'warn';
package/lib/transform.js CHANGED
@@ -56,7 +56,7 @@ const builder_1 = require("./builder");
56
56
  */
57
57
  function transformVTDirective(options = {}) {
58
58
  const i18nInstance = options.i18n;
59
- const mode = shared_1.isString(options.mode) && ['composition', 'legacy'].includes(options.mode)
59
+ const mode = (0, shared_1.isString)(options.mode) && ['composition', 'legacy'].includes(options.mode)
60
60
  ? options.mode
61
61
  : 'composition';
62
62
  return (dir, node, context) => {
@@ -67,7 +67,7 @@ function transformVTDirective(options = {}) {
67
67
  // TODO: throw error with context.OnError
68
68
  // NOTE: We need to support from @vue/compiler-core
69
69
  // https://github.com/vuejs/vue-next/issues/1147
70
- report_1.report(1 /* UNEXPECTED_DIRECTIVE_EXPRESSION */, {
70
+ (0, report_1.report)(1 /* ReportCodes.UNEXPECTED_DIRECTIVE_EXPRESSION */, {
71
71
  mode: 'error',
72
72
  args: [node.loc.source || ''],
73
73
  loc: node.loc
@@ -77,7 +77,7 @@ function transformVTDirective(options = {}) {
77
77
  // TODO: throw error with context.OnError
78
78
  // NOTE: We need to support from @vue/compiler-core
79
79
  // https://github.com/vuejs/vue-next/issues/1147
80
- report_1.report(7 /* ORVERRIDE_ELEMENT_CHILDREN */, {
80
+ (0, report_1.report)(7 /* ReportCodes.ORVERRIDE_ELEMENT_CHILDREN */, {
81
81
  mode: 'error',
82
82
  args: [node.loc.source || ''],
83
83
  loc: node.loc
@@ -85,24 +85,24 @@ function transformVTDirective(options = {}) {
85
85
  node.children.length = 0;
86
86
  }
87
87
  if (dir.modifiers.includes('preserve')) {
88
- report_1.report(6 /* NOT_SUPPORTED_PRESERVE */, {
88
+ (0, report_1.report)(6 /* ReportCodes.NOT_SUPPORTED_PRESERVE */, {
89
89
  args: [node.loc.source || ''],
90
90
  loc: node.loc
91
91
  });
92
92
  }
93
93
  if (isSimpleExpressionNode(exp)) {
94
94
  if (isConstant(exp) && i18nInstance) {
95
- const { status, value } = transpiler_1.evaluateValue(exp.content);
95
+ const { status, value } = (0, transpiler_1.evaluateValue)(exp.content);
96
96
  if (status === 'ng') {
97
- report_1.report(3 /* FAILED_VALUE_EVALUATION */, {
97
+ (0, report_1.report)(3 /* ReportCodes.FAILED_VALUE_EVALUATION */, {
98
98
  args: [node.loc.source || ''],
99
99
  loc: node.loc
100
100
  });
101
101
  return { props: [] };
102
102
  }
103
103
  const [parsedValue, parseStatus] = parseValue(value);
104
- if (parseStatus !== 0 /* SUCCESS */) {
105
- report_1.report(parseStatus, { args: [node.loc.source || ''], loc: node.loc });
104
+ if (parseStatus !== 0 /* ReportCodes.SUCCESS */) {
105
+ (0, report_1.report)(parseStatus, { args: [node.loc.source || ''], loc: node.loc });
106
106
  return { props: [] };
107
107
  }
108
108
  const global = i18nInstance.mode === 'composition'
@@ -110,21 +110,21 @@ function transformVTDirective(options = {}) {
110
110
  : i18nInstance.global.__composer; // eslint-disable-line @typescript-eslint/no-explicit-any
111
111
  const content = global.t(...makeParams(parsedValue));
112
112
  node.children.push({
113
- type: 2 /* TEXT */,
113
+ type: 2 /* NodeTypes.TEXT */,
114
114
  content
115
115
  });
116
116
  return { props: [] };
117
117
  }
118
118
  else {
119
- const translationParams = transpiler_1.parseVTExpression(exp.content);
119
+ const translationParams = (0, transpiler_1.parseVTExpression)(exp.content);
120
120
  const code = generateTranslationCode(context, mode, translationParams);
121
121
  context.helper(compiler_dom_1.TO_DISPLAY_STRING);
122
122
  node.children.push({
123
- type: 5 /* INTERPOLATION */,
124
- content: compiler_dom_1.createCompoundExpression([
125
- compiler_dom_1.createSimpleExpression(code, false, loc,
123
+ type: 5 /* NodeTypes.INTERPOLATION */,
124
+ content: (0, compiler_dom_1.createCompoundExpression)([
125
+ (0, compiler_dom_1.createSimpleExpression)(code, false, loc,
126
126
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
- 0 /* NOT_CONSTANT */)
127
+ 0 /* ConstantTypes.NOT_CONSTANT */)
128
128
  ])
129
129
  });
130
130
  return { props: [] };
@@ -132,20 +132,20 @@ function transformVTDirective(options = {}) {
132
132
  }
133
133
  else if (isCompoundExpressionNode(exp)) {
134
134
  const content = exp.children.map(mapNodeContentHanlder).join('');
135
- const code = generateTranslationCode(context, mode, transpiler_1.parseVTExpression(content));
135
+ const code = generateTranslationCode(context, mode, (0, transpiler_1.parseVTExpression)(content));
136
136
  context.helper(compiler_dom_1.TO_DISPLAY_STRING);
137
137
  node.children.push({
138
- type: 5 /* INTERPOLATION */,
139
- content: compiler_dom_1.createCompoundExpression([
140
- compiler_dom_1.createSimpleExpression(code, false, loc,
138
+ type: 5 /* NodeTypes.INTERPOLATION */,
139
+ content: (0, compiler_dom_1.createCompoundExpression)([
140
+ (0, compiler_dom_1.createSimpleExpression)(code, false, loc,
141
141
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
- 0 /* NOT_CONSTANT */)
142
+ 0 /* ConstantTypes.NOT_CONSTANT */)
143
143
  ])
144
144
  });
145
145
  return { props: [] };
146
146
  }
147
147
  else {
148
- report_1.report(2 /* NOT_SUPPORTED */, {
148
+ (0, report_1.report)(2 /* ReportCodes.NOT_SUPPORTED */, {
149
149
  args: [node.loc.source || ''],
150
150
  loc: node.loc
151
151
  });
@@ -155,10 +155,10 @@ function transformVTDirective(options = {}) {
155
155
  }
156
156
  exports.transformVTDirective = transformVTDirective;
157
157
  function isSimpleExpressionNode(node) {
158
- return node != null && node.type === 4 /* SIMPLE_EXPRESSION */;
158
+ return node != null && node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */;
159
159
  }
160
160
  function isCompoundExpressionNode(node) {
161
- return node != null && node.type === 8 /* COMPOUND_EXPRESSION */;
161
+ return node != null && node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */;
162
162
  }
163
163
  function isConstant(node) {
164
164
  if ('isConstant' in node) {
@@ -168,17 +168,17 @@ function isConstant(node) {
168
168
  }
169
169
  else if ('constType' in node) {
170
170
  // for v3.0.3 or later
171
- return node.constType <= 3 /* CAN_STRINGIFY */;
171
+ return node.constType <= 3 /* ConstantTypes.CAN_STRINGIFY */;
172
172
  }
173
173
  else {
174
174
  throw Error('unexpected error');
175
175
  }
176
176
  }
177
177
  function mapNodeContentHanlder(value) {
178
- if (shared_1.isString(value)) {
178
+ if ((0, shared_1.isString)(value)) {
179
179
  return value;
180
180
  }
181
- else if (shared_1.isSymbol(value)) {
181
+ else if ((0, shared_1.isSymbol)(value)) {
182
182
  return value.description || '';
183
183
  }
184
184
  else if (isSimpleExpressionNode(value)) {
@@ -187,8 +187,8 @@ function mapNodeContentHanlder(value) {
187
187
  else if (isCompoundExpressionNode(value)) {
188
188
  return value.children.map(mapNodeContentHanlder).join('');
189
189
  }
190
- else if (compiler_dom_1.isText(value)) {
191
- if (shared_1.isString(value.content)) {
190
+ else if ((0, compiler_dom_1.isText)(value)) {
191
+ if ((0, shared_1.isString)(value.content)) {
192
192
  return value.content;
193
193
  }
194
194
  else if (isSimpleExpressionNode(value.content)) {
@@ -206,17 +206,17 @@ function mapNodeContentHanlder(value) {
206
206
  }
207
207
  }
208
208
  function parseValue(value) {
209
- if (shared_1.isString(value)) {
210
- return [{ path: value }, 0 /* SUCCESS */];
209
+ if ((0, shared_1.isString)(value)) {
210
+ return [{ path: value }, 0 /* ReportCodes.SUCCESS */];
211
211
  }
212
- else if (shared_1.isObject(value)) {
212
+ else if ((0, shared_1.isObject)(value)) {
213
213
  if (!('path' in value)) {
214
- return [null, 4 /* REQUIRED_PARAMETER */];
214
+ return [null, 4 /* ReportCodes.REQUIRED_PARAMETER */];
215
215
  }
216
- return [value, 0 /* SUCCESS */];
216
+ return [value, 0 /* ReportCodes.SUCCESS */];
217
217
  }
218
218
  else {
219
- return [null, 5 /* INVALID_PARAMETER_TYPE */];
219
+ return [null, 5 /* ReportCodes.INVALID_PARAMETER_TYPE */];
220
220
  }
221
221
  }
222
222
  function makeParams(value) {
@@ -224,13 +224,13 @@ function makeParams(value) {
224
224
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
225
225
  const options = {};
226
226
  const named = args || {};
227
- if (shared_1.isString(locale)) {
227
+ if ((0, shared_1.isString)(locale)) {
228
228
  options.locale = locale;
229
229
  }
230
- if (shared_1.isNumber(choice)) {
230
+ if ((0, shared_1.isNumber)(choice)) {
231
231
  options.plural = choice;
232
232
  }
233
- if (shared_1.isNumber(plural)) {
233
+ if ((0, shared_1.isNumber)(plural)) {
234
234
  options.plural = plural;
235
235
  }
236
236
  return [path, named, options];
@@ -242,10 +242,10 @@ function generateTranslationCode(context, mode, params) {
242
242
  }
243
243
  function generateComposableCode(context, params) {
244
244
  const baseCode = `${context.prefixIdentifiers ? '_ctx.' : ''}t`;
245
- const builder = builder_1.createContentBuilder();
245
+ const builder = (0, builder_1.createContentBuilder)();
246
246
  builder.push(`${baseCode}(`);
247
247
  // generate path
248
- builder.push(`${shared_1.toDisplayString(params.path)}`);
248
+ builder.push(`${(0, shared_1.toDisplayString)(params.path)}`);
249
249
  // generate named
250
250
  builder.push(`, { `);
251
251
  generateNamedCode(builder, params.named);
@@ -253,13 +253,13 @@ function generateComposableCode(context, params) {
253
253
  // generate options
254
254
  builder.push(`, { `);
255
255
  if (params.options.locale) {
256
- builder.push(`locale: ${shared_1.toDisplayString(params.options.locale)}`);
256
+ builder.push(`locale: ${(0, shared_1.toDisplayString)(params.options.locale)}`);
257
257
  }
258
258
  if (params.options.plural) {
259
259
  if (params.options.locale) {
260
260
  builder.push(', ');
261
261
  }
262
- builder.push(`plural: ${shared_1.toDisplayString(params.options.plural)}`);
262
+ builder.push(`plural: ${(0, shared_1.toDisplayString)(params.options.plural)}`);
263
263
  }
264
264
  builder.push(` }`);
265
265
  builder.push(`)`);
@@ -272,27 +272,27 @@ function generateNamedCode(builder, named) {
272
272
  keys.forEach(k => {
273
273
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
274
274
  const v = named[k];
275
- if (shared_1.isObject(v)) {
275
+ if ((0, shared_1.isObject)(v)) {
276
276
  builder.push(`${k}: { `);
277
277
  generateNamedCode(builder, v);
278
278
  builder.push(` }`);
279
279
  }
280
280
  else {
281
- builder.push(`${k}: ${shared_1.toDisplayString(v)}`);
281
+ builder.push(`${k}: ${(0, shared_1.toDisplayString)(v)}`);
282
282
  }
283
283
  });
284
284
  }
285
285
  function generateLegacyCode(context, params) {
286
286
  const mode = !params.options.plural ? 'basic' : 'plural';
287
287
  const baseCode = `${context.prefixIdentifiers ? '_ctx.' : ''}${mode === 'basic' ? '$t' : '$tc'}`;
288
- const builder = builder_1.createContentBuilder();
288
+ const builder = (0, builder_1.createContentBuilder)();
289
289
  builder.push(`${baseCode}(`);
290
290
  // generate path
291
- builder.push(`${shared_1.toDisplayString(params.path)}`);
291
+ builder.push(`${(0, shared_1.toDisplayString)(params.path)}`);
292
292
  if (mode === 'basic') {
293
293
  // generate locale
294
- if (shared_1.isString(params.options.locale)) {
295
- builder.push(`, ${shared_1.toDisplayString(params.options.locale)}`);
294
+ if ((0, shared_1.isString)(params.options.locale)) {
295
+ builder.push(`, ${(0, shared_1.toDisplayString)(params.options.locale)}`);
296
296
  }
297
297
  // generate named
298
298
  builder.push(`, { `);
@@ -301,10 +301,10 @@ function generateLegacyCode(context, params) {
301
301
  }
302
302
  else {
303
303
  // generaete plural
304
- builder.push(`, ${shared_1.toDisplayString(params.options.plural)}`);
305
- if (shared_1.isString(params.options.locale)) {
304
+ builder.push(`, ${(0, shared_1.toDisplayString)(params.options.plural)}`);
305
+ if ((0, shared_1.isString)(params.options.locale)) {
306
306
  // generate locale
307
- builder.push(`, ${shared_1.toDisplayString(params.options.locale)}`);
307
+ builder.push(`, ${(0, shared_1.toDisplayString)(params.options.locale)}`);
308
308
  }
309
309
  else {
310
310
  // generate named
package/lib/transpiler.js CHANGED
@@ -6,7 +6,7 @@ const parser_1 = require("@babel/parser");
6
6
  function evaluateValue(expression) {
7
7
  const ret = { status: 'ng', value: undefined };
8
8
  try {
9
- const ast = parser_1.parse(`const a = ${expression.trim()}`);
9
+ const ast = (0, parser_1.parse)(`const a = ${expression.trim()}`);
10
10
  const node = ast.program.body[0].declarations[0].init;
11
11
  if (node.type === 'StringLiteral' || node.type === 'ObjectExpression') {
12
12
  const val = new Function(`return ${expression.trim()}`)();
@@ -25,7 +25,7 @@ function parseVTExpression(expression) {
25
25
  options: {}
26
26
  };
27
27
  try {
28
- const ast = parser_1.parse(`const a = ${expression.trim()}`);
28
+ const ast = (0, parser_1.parse)(`const a = ${expression.trim()}`);
29
29
  const node = ast.program.body[0].declarations[0].init;
30
30
  if (node.type === 'StringLiteral') {
31
31
  ret.path = node.extra.raw;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intlify/vue-i18n-extensions",
3
3
  "description": "vue-i18n extensions",
4
- "version": "4.0.0",
4
+ "version": "5.0.1",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -24,9 +24,9 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@babel/parser": "^7.15.2",
27
+ "@babel/parser": "^7.20.0",
28
28
  "@intlify/shared": "^9.0.0",
29
- "@vue/compiler-dom": "^3.1.5",
29
+ "@vue/compiler-dom": "^3.2.45",
30
30
  "vue-i18n": "^9.0.0"
31
31
  },
32
32
  "devDependencies": {
@@ -34,32 +34,31 @@
34
34
  "@microsoft/api-extractor": "^7.18.4",
35
35
  "@secretlint/secretlint-rule-preset-recommend": "^3.3.0",
36
36
  "@types/jest": "^26.0.24",
37
- "@types/node": "^16.4.13",
38
- "@typescript-eslint/eslint-plugin": "^5.0.0",
39
- "@typescript-eslint/parser": "^5.0.0",
40
- "@vue/compiler-sfc": "^3.1.5",
41
- "@vue/compiler-ssr": "^3.1.5",
42
- "@vue/runtime-dom": "^3.1.5",
43
- "@vue/server-renderer": "^3.1.5",
37
+ "@types/node": "^18.11.17",
38
+ "@typescript-eslint/eslint-plugin": "^5.46.1",
39
+ "@typescript-eslint/parser": "^5.46.1",
40
+ "@vue/compiler-sfc": "^3.2.45",
41
+ "@vue/compiler-ssr": "^3.2.45",
42
+ "@vue/runtime-dom": "^3.2.45",
43
+ "@vue/server-renderer": "^3.2.45",
44
44
  "api-docs-gen": "^0.4.0",
45
45
  "babel-loader": "^8.2.0",
46
- "eslint": "^7.32.0",
47
- "eslint-config-prettier": "^8.3.0",
48
- "eslint-plugin-prettier": "^3.4.0",
49
- "eslint-plugin-vue-libs": "^4.0.0",
46
+ "eslint": "^8.30.0",
47
+ "eslint-config-prettier": "^8.5.0",
48
+ "eslint-plugin-prettier": "^4.2.1",
50
49
  "jest": "^27.0.6",
51
50
  "jest-puppeteer": "^6.0.0",
52
51
  "jest-watch-typeahead": "^1.0.0",
53
52
  "lint-staged": "^11.0.0",
54
53
  "npm-run-all": "^4.1.5",
55
54
  "opener": "^1.5.2",
55
+ "prettier": "^2.8.1",
56
56
  "puppeteer": "^12.0.0",
57
57
  "secretlint": "^3.3.0",
58
58
  "shipjs": "^0.24.0",
59
59
  "ts-jest": "^27.0.4",
60
- "typescript": "^4.3.5",
61
- "typescript-eslint-language-service": "^5.0.0",
62
- "vue": "^3.1.5",
60
+ "typescript": "^4.9.1",
61
+ "vue": "^3.2.45",
63
62
  "vue-loader": "^16.2.0",
64
63
  "webpack": "^5.49.0",
65
64
  "webpack-cli": "^4.7.2",
@@ -109,7 +108,7 @@
109
108
  "scripts": {
110
109
  "build": "yarn build:transpile && yarn build:extract && yarn build:docs",
111
110
  "build:docs": "api-docs-gen ./temp/vue-i18n-extensions.api.json -c ./docsgen.config.js -o ./docs",
112
- "build:extract": "api-extractor run -l -c ./api-extractor.json",
111
+ "build:extract": "api-extractor run -l -c ./api-extractor.json --typescript-compiler-folder node_modules/typescript",
113
112
  "build:transpile": "tsc -p .",
114
113
  "clean": "npm-run-all clean:*",
115
114
  "clean:cache:jest": "jest --clearCache",
@@ -119,10 +118,10 @@
119
118
  "coverage": "opener coverage/lcov-report/index.html",
120
119
  "example": "webpack serve --config example/webpack.config.js --inline --hot",
121
120
  "fix": "npm-run-all --parallel lint:eslint:fix format:fix",
122
- "format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{js,json,html}'",
121
+ "format": "prettier --config .prettierrc --ignore-path .prettierignore --list-different '**/*.{js,json,html}'",
123
122
  "format:fix": "yarn format --write",
124
123
  "lint": "npm-run-all --parallel lint:eslint lint:secret",
125
- "lint:eslint": "eslint ./src ./test --ext .ts",
124
+ "lint:eslint": "eslint ./src ./test --ext .ts --cache",
126
125
  "lint:eslint:fix": "yarn lint:eslint --fix",
127
126
  "lint:secret": "npx secretlint \"**/*\"",
128
127
  "release:prepare": "shipjs prepare",