@intlify/bundle-utils 5.1.0 → 5.1.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/lib/js.js +28 -11
- package/package.json +1 -3
package/lib/js.js
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Code generator for i18n js resource
|
|
4
4
|
*/
|
|
5
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
-
};
|
|
8
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
6
|
exports.generate = void 0;
|
|
10
7
|
const shared_1 = require("@intlify/shared");
|
|
11
8
|
const acorn_1 = require("acorn");
|
|
12
9
|
const estree_walker_1 = require("estree-walker");
|
|
13
|
-
const esquery_1 = __importDefault(require("esquery"));
|
|
14
10
|
const codegen_1 = require("./codegen");
|
|
15
11
|
/**
|
|
16
12
|
* @internal
|
|
@@ -42,20 +38,18 @@ function generate(targetSource, { type = 'plain', bridge = false, exportESM = fa
|
|
|
42
38
|
sourceFile: filename,
|
|
43
39
|
allowImportExportEverywhere: true
|
|
44
40
|
});
|
|
45
|
-
const
|
|
46
|
-
console.log('astExportDefaultWithObject', astExportDefaultWithObject);
|
|
41
|
+
const exportResult = scanAst(ast);
|
|
47
42
|
if (!allowDynamic) {
|
|
48
|
-
if (!astExportDefaultWithObject.length) {
|
|
43
|
+
// if (!astExportDefaultWithObject.length) {
|
|
44
|
+
if (!exportResult || exportResult !== 'object') {
|
|
49
45
|
throw new Error(`You need to define an object as the locale message with 'export default'.`);
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
else {
|
|
53
|
-
|
|
54
|
-
if (!astExportDefault.length) {
|
|
49
|
+
if (!exportResult) {
|
|
55
50
|
throw new Error(`You need to define 'export default' that will return the locale messages.`);
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
if (!astExportDefaultWithObject.length) {
|
|
52
|
+
if (exportResult !== 'object') {
|
|
59
53
|
/**
|
|
60
54
|
* NOTE:
|
|
61
55
|
* If `allowDynamic` is `true`, do not transform the code by this function, return it as is.
|
|
@@ -88,6 +82,29 @@ function generate(targetSource, { type = 'plain', bridge = false, exportESM = fa
|
|
|
88
82
|
};
|
|
89
83
|
}
|
|
90
84
|
exports.generate = generate;
|
|
85
|
+
function scanAst(ast) {
|
|
86
|
+
if (ast.type !== 'Program') {
|
|
87
|
+
throw new Error('Invalid AST: does not have Program node');
|
|
88
|
+
}
|
|
89
|
+
let ret = false;
|
|
90
|
+
for (const node of ast.body) {
|
|
91
|
+
if (node.type === 'ExportDefaultDeclaration') {
|
|
92
|
+
if (node.declaration.type === 'ObjectExpression') {
|
|
93
|
+
ret = 'object';
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
else if (node.declaration.type === 'FunctionDeclaration') {
|
|
97
|
+
ret = 'function';
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
else if (node.declaration.type === 'ArrowFunctionExpression') {
|
|
101
|
+
ret = 'arrow-function';
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return ret;
|
|
107
|
+
}
|
|
91
108
|
function generateNode(generator, node, options, injector) {
|
|
92
109
|
const propsCountStack = [];
|
|
93
110
|
const pathStack = [];
|
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": "5.1.
|
|
4
|
+
"version": "5.1.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -21,14 +21,12 @@
|
|
|
21
21
|
"@intlify/message-compiler": "next",
|
|
22
22
|
"@intlify/shared": "next",
|
|
23
23
|
"acorn": "^8.8.2",
|
|
24
|
-
"esquery": "^1.5.0",
|
|
25
24
|
"estree-walker": "^2.0.2",
|
|
26
25
|
"jsonc-eslint-parser": "^1.0.1",
|
|
27
26
|
"source-map": "0.6.1",
|
|
28
27
|
"yaml-eslint-parser": "^0.3.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@types/esquery": "^1.0.2",
|
|
32
30
|
"@types/estree": "^1.0.0"
|
|
33
31
|
},
|
|
34
32
|
"engines": {
|