@teambit/dependencies 1.0.449 → 1.0.450
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/artifacts/__bit_junit.xml +35 -67
- package/artifacts/schema.json +217 -97
- package/dist/dependencies.main.runtime.js.map +1 -1
- package/dist/files-dependency-builder/detector-hook.d.ts +3 -2
- package/dist/files-dependency-builder/detector-hook.js +6 -4
- package/dist/files-dependency-builder/detector-hook.js.map +1 -1
- package/dist/files-dependency-builder/filing-cabinet/index.js +3 -2
- package/dist/files-dependency-builder/filing-cabinet/index.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.d.ts +0 -10
- package/dist/files-dependency-builder/precinct/index.js +10 -37
- package/dist/files-dependency-builder/precinct/index.js.map +1 -1
- package/dist/files-dependency-builder/precinct/index.spec.js +0 -210
- package/dist/files-dependency-builder/precinct/index.spec.js.map +1 -1
- package/files-dependency-builder/detector-hook.ts +6 -2
- package/files-dependency-builder/filing-cabinet/index.ts +2 -2
- package/files-dependency-builder/precinct/index.spec.ts +0 -244
- package/files-dependency-builder/precinct/index.ts +8 -39
- package/package.json +14 -14
- /package/dist/{preview-1730344956084.js → preview-1730431405757.js} +0 -0
@@ -1,165 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
function _chai() {
|
4
|
-
const data = require("chai");
|
5
|
-
_chai = function () {
|
6
|
-
return data;
|
7
|
-
};
|
8
|
-
return data;
|
9
|
-
}
|
10
3
|
const assert = require('assert');
|
11
|
-
const fs = require('fs');
|
12
4
|
const path = require('path');
|
13
5
|
const rewire = require('rewire');
|
14
6
|
const sinon = require('sinon');
|
15
7
|
const fixtures = '../fixtures/precinct';
|
16
8
|
const fixturesFullPath = path.resolve(__dirname, fixtures);
|
17
|
-
const exampleASTPath = path.join(fixtures, 'exampleAST');
|
18
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
19
|
-
const ast = require(exampleASTPath);
|
20
9
|
const precinctNonWired = rewire('./');
|
21
10
|
const precinct = precinctNonWired.default;
|
22
|
-
function read(filename) {
|
23
|
-
return fs.readFileSync(path.join(fixturesFullPath, filename), 'utf8');
|
24
|
-
}
|
25
11
|
describe('node-precinct', () => {
|
26
|
-
it('accepts an AST', () => {
|
27
|
-
const deps = precinct(ast);
|
28
|
-
const depsKeys = Object.keys(deps);
|
29
|
-
assert(depsKeys.length === 1);
|
30
|
-
});
|
31
|
-
it('dangles off a given ast', () => {
|
32
|
-
precinct(ast);
|
33
|
-
assert.deepEqual(precinct.ast, ast);
|
34
|
-
});
|
35
|
-
it('dangles off the parsed ast from a .js file', () => {
|
36
|
-
precinct(read('amd.js'));
|
37
|
-
assert.ok(precinct.ast);
|
38
|
-
assert.notDeepEqual(precinct.ast, ast);
|
39
|
-
});
|
40
|
-
it('dangles off the parsed ast from a scss detective', () => {
|
41
|
-
precinct(read('styles.scss'), 'scss');
|
42
|
-
assert.notDeepEqual(precinct.ast, {});
|
43
|
-
});
|
44
|
-
it('dangles off the parsed ast from a sass detective', () => {
|
45
|
-
precinct(read('styles.sass'), 'sass');
|
46
|
-
assert.notDeepEqual(precinct.ast, {});
|
47
|
-
});
|
48
|
-
it('grabs dependencies of amd modules', () => {
|
49
|
-
const amd = precinct(read('amd.js'));
|
50
|
-
assert(amd.indexOf('./a') !== -1);
|
51
|
-
assert(amd.indexOf('./b') !== -1);
|
52
|
-
assert(amd.length === 2);
|
53
|
-
});
|
54
|
-
it('grabs dependencies of commonjs modules', () => {
|
55
|
-
const cjs = precinct(read('commonjs.js'));
|
56
|
-
(0, _chai().expect)(cjs).to.have.property('./a');
|
57
|
-
(0, _chai().expect)(cjs).to.have.property('./b');
|
58
|
-
assert(Object.keys(cjs).length === 2);
|
59
|
-
});
|
60
|
-
it('grabs dependencies of es6 modules', () => {
|
61
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
62
|
-
console.log(square(11)); // 121
|
63
|
-
console.log(diag(4, 3)); // 5`);
|
64
|
-
(0, _chai().expect)(cjs).to.have.property('lib');
|
65
|
-
assert(Object.keys(cjs).length === 1);
|
66
|
-
});
|
67
|
-
it('grabs dependencies of es6 modules with embedded jsx', () => {
|
68
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
69
|
-
const tmpl = <jsx />;`);
|
70
|
-
(0, _chai().expect)(cjs).to.have.property('lib');
|
71
|
-
assert(Object.keys(cjs).length === 1);
|
72
|
-
});
|
73
|
-
it('grabs dependencies of es6 modules with embedded es7', () => {
|
74
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
75
|
-
async function foo() {}`);
|
76
|
-
(0, _chai().expect)(cjs).to.have.property('lib');
|
77
|
-
assert(Object.keys(cjs).length === 1);
|
78
|
-
});
|
79
|
-
it('throws errors of es6 modules with syntax errors', () => {
|
80
|
-
const precinctFunc = () => precinct(`import { square, diag } from 'lib' // error, semicolon
|
81
|
-
console.log(square(11)); // 121
|
82
|
-
console.log(diag(4, 3); // 5, error, missing paren`);
|
83
|
-
(0, _chai().expect)(precinctFunc).to.throw();
|
84
|
-
});
|
85
|
-
|
86
|
-
// this is for supporting PostCSS dialect. The implementation is not merged to this project.
|
87
|
-
// see the following PR of node-precinct: https://github.com/dependents/node-precinct/pull/40
|
88
|
-
it.skip('grabs dependencies of css files', () => {
|
89
|
-
const css = precinct(read('styles.css'), 'css');
|
90
|
-
(0, _chai().expect)(css).to.have.property('foo.css');
|
91
|
-
(0, _chai().expect)(css).to.have.property('baz.css');
|
92
|
-
(0, _chai().expect)(css).to.have.property('bla.css');
|
93
|
-
(0, _chai().expect)(css).to.have.property('another.css');
|
94
|
-
});
|
95
|
-
it('grabs dependencies of scss files', function () {
|
96
|
-
const scss = precinct(read('styles.scss'), 'scss');
|
97
|
-
assert.deepEqual(scss, ['_foo', 'baz.scss']);
|
98
|
-
});
|
99
|
-
it('grabs dependencies of sass files', () => {
|
100
|
-
const sass = precinct(read('styles.sass'), 'sass');
|
101
|
-
assert.deepEqual(sass, ['_foo']);
|
102
|
-
});
|
103
|
-
it('grabs dependencies of stylus files', () => {
|
104
|
-
const result = precinct(read('styles.styl'), 'stylus');
|
105
|
-
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
106
|
-
assert.deepEqual(result, expected);
|
107
|
-
});
|
108
|
-
it('grabs dependencies of less files', () => {
|
109
|
-
const result = precinct(read('styles.less'), 'less');
|
110
|
-
const expected = ['_foo', '_bar.css', 'baz.less'];
|
111
|
-
assert.deepEqual(result, expected);
|
112
|
-
});
|
113
|
-
// todo: fix this one once we have a way to ignore some component files from compiling/parsing altogether
|
114
|
-
// uncomment typescript.ts
|
115
|
-
it.skip('grabs dependencies of typescript files', () => {
|
116
|
-
const result = precinct(read('typescript.ts'), 'ts');
|
117
|
-
const expected = ['fs', 'lib', './bar', './my-module.js', './ZipCodeValidator'];
|
118
|
-
assert.deepEqual(Object.keys(result), expected);
|
119
|
-
});
|
120
|
-
it('throws errors of typescript modules with syntax errors', () => {
|
121
|
-
const precinctFunc = () => precinct(`import { square, diag } from 'lib';
|
122
|
-
console.log(diag(4, 3); // error, missing bracket
|
123
|
-
`);
|
124
|
-
(0, _chai().expect)(precinctFunc).to.throw();
|
125
|
-
});
|
126
|
-
it('supports the object form of type configuration', () => {
|
127
|
-
const result = precinct(read('styles.styl'), {
|
128
|
-
type: 'stylus'
|
129
|
-
});
|
130
|
-
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
131
|
-
assert.deepEqual(result, expected);
|
132
|
-
});
|
133
|
-
it('yields no dependencies for es6 modules with no imports', () => {
|
134
|
-
const cjs = precinct(`export const sqrt = Math.sqrt;
|
135
|
-
export function square(x) {
|
136
|
-
return x * x;
|
137
|
-
}
|
138
|
-
export function diag(x, y) {
|
139
|
-
return sqrt(square(x) + square(y));
|
140
|
-
}
|
141
|
-
`);
|
142
|
-
assert.equal(Object.keys(cjs).length, 0);
|
143
|
-
});
|
144
|
-
it('yields no dependencies for non-modules', () => {
|
145
|
-
const none = precinct(`var a = new window.Foo();`);
|
146
|
-
assert.equal(Object.keys(none).length, 0);
|
147
|
-
});
|
148
|
-
it('throw on unparsable .js files', () => {
|
149
|
-
assert.throws(() => {
|
150
|
-
precinct(`{
|
151
|
-
"very invalid": "javascript",
|
152
|
-
"this", "is actually json",
|
153
|
-
"But" not even valid json.
|
154
|
-
}
|
155
|
-
`);
|
156
|
-
}, SyntaxError);
|
157
|
-
});
|
158
|
-
it('does not blow up when parsing a gruntfile #2', () => {
|
159
|
-
assert.doesNotThrow(() => {
|
160
|
-
precinct(read('Gruntfile.js'));
|
161
|
-
});
|
162
|
-
});
|
163
12
|
describe('paperwork', () => {
|
164
13
|
// todo: currently it doesn't work because we set it with bit-no-check
|
165
14
|
it.skip('returns the dependencies for the given filepath', () => {
|
@@ -236,65 +85,6 @@ export function diag(x, y) {
|
|
236
85
|
});
|
237
86
|
});
|
238
87
|
});
|
239
|
-
describe('when given a configuration object', () => {
|
240
|
-
it('passes amd config to the amd detective', () => {
|
241
|
-
const config = {
|
242
|
-
amd: {
|
243
|
-
skipLazyLoaded: true
|
244
|
-
}
|
245
|
-
};
|
246
|
-
const deps = precinct(read('amd.js'), config);
|
247
|
-
assert.deepEqual(deps, ['./a', './b']);
|
248
|
-
});
|
249
|
-
describe('that sets mixedImports for es6', () => {
|
250
|
-
describe('for a file identified as es6', () => {
|
251
|
-
it('returns both the commonjs and es6 dependencies', () => {
|
252
|
-
const deps = precinct(`import foo from './foo';
|
253
|
-
var bar = require('./bar');`, {
|
254
|
-
es6: {
|
255
|
-
mixedImports: true
|
256
|
-
}
|
257
|
-
});
|
258
|
-
assert.equal(Object.keys(deps).length, 2);
|
259
|
-
});
|
260
|
-
});
|
261
|
-
describe('for a file identified as cjs', () => {
|
262
|
-
it('returns both the commonjs and es6 dependencies', () => {
|
263
|
-
const deps = precinct(`var bar = require('./bar');
|
264
|
-
import foo from './foo';`, {
|
265
|
-
es6: {
|
266
|
-
mixedImports: true
|
267
|
-
}
|
268
|
-
});
|
269
|
-
assert.equal(Object.keys(deps).length, 2);
|
270
|
-
});
|
271
|
-
});
|
272
|
-
});
|
273
|
-
});
|
274
|
-
describe('when lazy exported dependencies in CJS', () => {
|
275
|
-
it('grabs those lazy dependencies', () => {
|
276
|
-
const cjs = precinct(read('cjsExportLazy.js'));
|
277
|
-
(0, _chai().expect)(cjs).to.have.property('./amd');
|
278
|
-
(0, _chai().expect)(cjs).to.have.property('./es6');
|
279
|
-
(0, _chai().expect)(cjs).to.have.property('./es7');
|
280
|
-
assert.equal(Object.keys(cjs).length, 3);
|
281
|
-
});
|
282
|
-
});
|
283
|
-
describe('when given an es6 file', () => {
|
284
|
-
describe('that uses CJS imports for lazy dependencies', () => {
|
285
|
-
it('grabs the lazy imports', () => {
|
286
|
-
const es6 = precinct(read('es6MixedExportLazy.js'), {
|
287
|
-
es6: {
|
288
|
-
mixedImports: true
|
289
|
-
}
|
290
|
-
});
|
291
|
-
(0, _chai().expect)(es6).to.have.property('./amd');
|
292
|
-
(0, _chai().expect)(es6).to.have.property('./es6');
|
293
|
-
(0, _chai().expect)(es6).to.have.property('./es7');
|
294
|
-
assert.equal(Object.keys(es6).length, 3);
|
295
|
-
});
|
296
|
-
});
|
297
|
-
});
|
298
88
|
});
|
299
89
|
|
300
90
|
//# sourceMappingURL=index.spec.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_chai","data","require","assert","fs","path","rewire","sinon","fixtures","fixturesFullPath","resolve","__dirname","exampleASTPath","join","ast","precinctNonWired","precinct","default","read","filename","readFileSync","describe","it","deps","depsKeys","Object","keys","length","deepEqual","ok","notDeepEqual","amd","indexOf","cjs","expect","to","have","property","precinctFunc","throw","skip","css","scss","sass","result","expected","type","equal","none","throws","SyntaxError","doesNotThrow","paperwork","includeCore","config","skipLazyLoaded","detector","detect","fileContent","isSupported","ext","envDetectors","result2","stub","returns","revert","__set__","args","es6","mixedImports"],"sources":["index.spec.ts"],"sourcesContent":["import { expect } from 'chai';\nimport { DependencyDetector } from '../detector-hook';\n\nconst assert = require('assert');\nconst fs = require('fs');\nconst path = require('path');\nconst rewire = require('rewire');\nconst sinon = require('sinon');\n\nconst fixtures = '../fixtures/precinct';\nconst fixturesFullPath = path.resolve(__dirname, fixtures);\nconst exampleASTPath = path.join(fixtures, 'exampleAST');\n// eslint-disable-next-line import/no-dynamic-require, global-require\nconst ast = require(exampleASTPath);\n\nconst precinctNonWired = rewire('./');\nconst precinct = precinctNonWired.default;\n\nfunction read(filename) {\n return fs.readFileSync(path.join(fixturesFullPath, filename), 'utf8');\n}\n\ndescribe('node-precinct', () => {\n it('accepts an AST', () => {\n const deps = precinct(ast);\n const depsKeys = Object.keys(deps);\n assert(depsKeys.length === 1);\n });\n\n it('dangles off a given ast', () => {\n precinct(ast);\n assert.deepEqual(precinct.ast, ast);\n });\n\n it('dangles off the parsed ast from a .js file', () => {\n precinct(read('amd.js'));\n assert.ok(precinct.ast);\n assert.notDeepEqual(precinct.ast, ast);\n });\n\n it('dangles off the parsed ast from a scss detective', () => {\n precinct(read('styles.scss'), 'scss');\n assert.notDeepEqual(precinct.ast, {});\n });\n\n it('dangles off the parsed ast from a sass detective', () => {\n precinct(read('styles.sass'), 'sass');\n assert.notDeepEqual(precinct.ast, {});\n });\n\n it('grabs dependencies of amd modules', () => {\n const amd = precinct(read('amd.js'));\n assert(amd.indexOf('./a') !== -1);\n assert(amd.indexOf('./b') !== -1);\n assert(amd.length === 2);\n });\n\n it('grabs dependencies of commonjs modules', () => {\n const cjs = precinct(read('commonjs.js'));\n expect(cjs).to.have.property('./a');\n expect(cjs).to.have.property('./b');\n assert(Object.keys(cjs).length === 2);\n });\n\n it('grabs dependencies of es6 modules', () => {\n const cjs = precinct(`import { square, diag } from 'lib';\nconsole.log(square(11)); // 121\nconsole.log(diag(4, 3)); // 5`);\n expect(cjs).to.have.property('lib');\n assert(Object.keys(cjs).length === 1);\n });\n\n it('grabs dependencies of es6 modules with embedded jsx', () => {\n const cjs = precinct(`import { square, diag } from 'lib';\nconst tmpl = <jsx />;`);\n expect(cjs).to.have.property('lib');\n assert(Object.keys(cjs).length === 1);\n });\n\n it('grabs dependencies of es6 modules with embedded es7', () => {\n const cjs = precinct(`import { square, diag } from 'lib';\nasync function foo() {}`);\n expect(cjs).to.have.property('lib');\n assert(Object.keys(cjs).length === 1);\n });\n\n it('throws errors of es6 modules with syntax errors', () => {\n const precinctFunc = () =>\n precinct(`import { square, diag } from 'lib' // error, semicolon\nconsole.log(square(11)); // 121\nconsole.log(diag(4, 3); // 5, error, missing paren`);\n expect(precinctFunc).to.throw();\n });\n\n // this is for supporting PostCSS dialect. The implementation is not merged to this project.\n // see the following PR of node-precinct: https://github.com/dependents/node-precinct/pull/40\n it.skip('grabs dependencies of css files', () => {\n const css = precinct(read('styles.css'), 'css');\n expect(css).to.have.property('foo.css');\n expect(css).to.have.property('baz.css');\n expect(css).to.have.property('bla.css');\n expect(css).to.have.property('another.css');\n });\n\n it('grabs dependencies of scss files', function () {\n const scss = precinct(read('styles.scss'), 'scss');\n assert.deepEqual(scss, ['_foo', 'baz.scss']);\n });\n\n it('grabs dependencies of sass files', () => {\n const sass = precinct(read('styles.sass'), 'sass');\n assert.deepEqual(sass, ['_foo']);\n });\n\n it('grabs dependencies of stylus files', () => {\n const result = precinct(read('styles.styl'), 'stylus');\n const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];\n\n assert.deepEqual(result, expected);\n });\n\n it('grabs dependencies of less files', () => {\n const result = precinct(read('styles.less'), 'less');\n const expected = ['_foo', '_bar.css', 'baz.less'];\n\n assert.deepEqual(result, expected);\n });\n // todo: fix this one once we have a way to ignore some component files from compiling/parsing altogether\n // uncomment typescript.ts\n it.skip('grabs dependencies of typescript files', () => {\n const result = precinct(read('typescript.ts'), 'ts');\n const expected = ['fs', 'lib', './bar', './my-module.js', './ZipCodeValidator'];\n\n assert.deepEqual(Object.keys(result), expected);\n });\n\n it('throws errors of typescript modules with syntax errors', () => {\n const precinctFunc = () =>\n precinct(`import { square, diag } from 'lib';\nconsole.log(diag(4, 3); // error, missing bracket\n`);\n expect(precinctFunc).to.throw();\n });\n\n it('supports the object form of type configuration', () => {\n const result = precinct(read('styles.styl'), { type: 'stylus' });\n const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];\n\n assert.deepEqual(result, expected);\n });\n\n it('yields no dependencies for es6 modules with no imports', () => {\n const cjs = precinct(`export const sqrt = Math.sqrt;\nexport function square(x) {\n return x * x;\n}\nexport function diag(x, y) {\n return sqrt(square(x) + square(y));\n}\n`);\n assert.equal(Object.keys(cjs).length, 0);\n });\n\n it('yields no dependencies for non-modules', () => {\n const none = precinct(`var a = new window.Foo();`);\n assert.equal(Object.keys(none).length, 0);\n });\n\n it('throw on unparsable .js files', () => {\n assert.throws(() => {\n precinct(`{\n\t\"very invalid\": \"javascript\",\n\t\"this\", \"is actually json\",\n\t\"But\" not even valid json.\n}\n`);\n }, SyntaxError);\n });\n\n it('does not blow up when parsing a gruntfile #2', () => {\n assert.doesNotThrow(() => {\n precinct(read('Gruntfile.js'));\n });\n });\n\n describe('paperwork', () => {\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('returns the dependencies for the given filepath', () => {\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);\n // todo: uncomment the next line and typescript.ts file once we have a way to ignore some component files from compiling/parsing altogether\n // assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);\n });\n\n it('throws if the file cannot be found', () => {\n assert.throws(() => {\n precinct.paperwork('foo');\n });\n });\n\n it('filters out core modules if options.includeCore is false', () => {\n const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {\n includeCore: false,\n });\n\n assert(!deps.length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('does not filter out core modules by default', () => {\n const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`);\n assert(Object.keys(deps).length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('supports passing detective configuration', () => {\n const config = {\n amd: {\n skipLazyLoaded: true,\n },\n };\n\n const deps = precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n includeCore: false,\n amd: config.amd,\n });\n assert.deepEqual(deps, ['./a', './b']);\n });\n\n it('supports passing env detectors', () => {\n const detector: DependencyDetector = {\n detect: (fileContent: string) => {\n return fileContent.indexOf('foo') === -1 ? [] : ['foo'];\n },\n isSupported: ({ ext }) => {\n return ext === '.foo';\n },\n type: 'foo',\n };\n const result = precinct.paperwork(`${fixturesFullPath}/foo.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result, []);\n\n const result2 = precinct.paperwork(`${fixturesFullPath}/bar.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result2, ['foo']);\n });\n\n describe('when given detective configuration', () => {\n // This test case doesn't fit the current implementation of precinct.\n it.skip('still does not filter out core module by default', () => {\n const stub = sinon.stub().returns([]);\n const revert = precinctNonWired.__set__('precinct', stub);\n\n precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n amd: {\n skipLazyLoaded: true,\n },\n });\n\n assert.equal(stub.args[0][1].includeCore, true);\n revert();\n });\n });\n });\n\n describe('when given a configuration object', () => {\n it('passes amd config to the amd detective', () => {\n const config = {\n amd: {\n skipLazyLoaded: true,\n },\n };\n\n const deps = precinct(read('amd.js'), config);\n assert.deepEqual(deps, ['./a', './b']);\n });\n\n describe('that sets mixedImports for es6', () => {\n describe('for a file identified as es6', () => {\n it('returns both the commonjs and es6 dependencies', () => {\n const deps = precinct(\n `import foo from './foo';\nvar bar = require('./bar');`,\n {\n es6: {\n mixedImports: true,\n },\n }\n );\n\n assert.equal(Object.keys(deps).length, 2);\n });\n });\n\n describe('for a file identified as cjs', () => {\n it('returns both the commonjs and es6 dependencies', () => {\n const deps = precinct(\n `var bar = require('./bar');\nimport foo from './foo';`,\n {\n es6: {\n mixedImports: true,\n },\n }\n );\n\n assert.equal(Object.keys(deps).length, 2);\n });\n });\n });\n });\n\n describe('when lazy exported dependencies in CJS', () => {\n it('grabs those lazy dependencies', () => {\n const cjs = precinct(read('cjsExportLazy.js'));\n expect(cjs).to.have.property('./amd');\n expect(cjs).to.have.property('./es6');\n expect(cjs).to.have.property('./es7');\n assert.equal(Object.keys(cjs).length, 3);\n });\n });\n\n describe('when given an es6 file', () => {\n describe('that uses CJS imports for lazy dependencies', () => {\n it('grabs the lazy imports', () => {\n const es6 = precinct(read('es6MixedExportLazy.js'), {\n es6: {\n mixedImports: true,\n },\n });\n expect(es6).to.have.property('./amd');\n expect(es6).to.have.property('./es6');\n expect(es6).to.have.property('./es7');\n assert.equal(Object.keys(es6).length, 3);\n });\n });\n });\n});\n"],"mappings":";;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,MAAME,MAAM,GAAGD,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAME,EAAE,GAAGF,OAAO,CAAC,IAAI,CAAC;AACxB,MAAMG,IAAI,GAAGH,OAAO,CAAC,MAAM,CAAC;AAC5B,MAAMI,MAAM,GAAGJ,OAAO,CAAC,QAAQ,CAAC;AAChC,MAAMK,KAAK,GAAGL,OAAO,CAAC,OAAO,CAAC;AAE9B,MAAMM,QAAQ,GAAG,sBAAsB;AACvC,MAAMC,gBAAgB,GAAGJ,IAAI,CAACK,OAAO,CAACC,SAAS,EAAEH,QAAQ,CAAC;AAC1D,MAAMI,cAAc,GAAGP,IAAI,CAACQ,IAAI,CAACL,QAAQ,EAAE,YAAY,CAAC;AACxD;AACA,MAAMM,GAAG,GAAGZ,OAAO,CAACU,cAAc,CAAC;AAEnC,MAAMG,gBAAgB,GAAGT,MAAM,CAAC,IAAI,CAAC;AACrC,MAAMU,QA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EAAE,MAAM;MAC5DC,EAAE,CAAC,wBAAwB,EAAE,MAAM;QACjC,MAAM8C,GAAG,GAAGpD,QAAQ,CAACE,IAAI,CAAC,uBAAuB,CAAC,EAAE;UAClDkD,GAAG,EAAE;YACHC,YAAY,EAAE;UAChB;QACF,CAAC,CAAC;QACF,IAAAnC,cAAM,EAACkC,GAAG,CAAC,CAACjC,EAAE,CAACC,IAAI,CAACC,QAAQ,CAAC,OAAO,CAAC;QACrC,IAAAH,cAAM,EAACkC,GAAG,CAAC,CAACjC,EAAE,CAACC,IAAI,CAACC,QAAQ,CAAC,OAAO,CAAC;QACrC,IAAAH,cAAM,EAACkC,GAAG,CAAC,CAACjC,EAAE,CAACC,IAAI,CAACC,QAAQ,CAAC,OAAO,CAAC;QACrClC,MAAM,CAAC4C,KAAK,CAACtB,MAAM,CAACC,IAAI,CAAC0C,GAAG,CAAC,CAACzC,MAAM,EAAE,CAAC,CAAC;MAC1C,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"names":["assert","require","path","rewire","sinon","fixtures","fixturesFullPath","resolve","__dirname","precinctNonWired","precinct","default","describe","it","skip","ok","Object","keys","paperwork","length","throws","deps","includeCore","config","amd","skipLazyLoaded","deepEqual","detector","detect","fileContent","indexOf","isSupported","ext","type","result","envDetectors","result2","stub","returns","revert","__set__","equal","args"],"sources":["index.spec.ts"],"sourcesContent":["import { DependencyDetector } from '../detector-hook';\n\nconst assert = require('assert');\nconst path = require('path');\nconst rewire = require('rewire');\nconst sinon = require('sinon');\n\nconst fixtures = '../fixtures/precinct';\nconst fixturesFullPath = path.resolve(__dirname, fixtures);\n\nconst precinctNonWired = rewire('./');\nconst precinct = precinctNonWired.default;\n\ndescribe('node-precinct', () => {\n describe('paperwork', () => {\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('returns the dependencies for the given filepath', () => {\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/es6.js`)).length);\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.scss`)).length);\n // todo: uncomment the next line and typescript.ts file once we have a way to ignore some component files from compiling/parsing altogether\n // assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/typescript.ts`)).length);\n assert.ok(Object.keys(precinct.paperwork(`${fixturesFullPath}/styles.css`)).length);\n });\n\n it('throws if the file cannot be found', () => {\n assert.throws(() => {\n precinct.paperwork('foo');\n });\n });\n\n it('filters out core modules if options.includeCore is false', () => {\n const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`, {\n includeCore: false,\n });\n\n assert(!deps.length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('does not filter out core modules by default', () => {\n const deps = precinct.paperwork(`${fixturesFullPath}/coreModules.js`);\n assert(Object.keys(deps).length);\n });\n\n // todo: currently it doesn't work because we set it with bit-no-check\n it.skip('supports passing detective configuration', () => {\n const config = {\n amd: {\n skipLazyLoaded: true,\n },\n };\n\n const deps = precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n includeCore: false,\n amd: config.amd,\n });\n assert.deepEqual(deps, ['./a', './b']);\n });\n\n it('supports passing env detectors', () => {\n const detector: DependencyDetector = {\n detect: (fileContent: string) => {\n return fileContent.indexOf('foo') === -1 ? [] : ['foo'];\n },\n isSupported: ({ ext }) => {\n return ext === '.foo';\n },\n type: 'foo',\n };\n const result = precinct.paperwork(`${fixturesFullPath}/foo.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result, []);\n\n const result2 = precinct.paperwork(`${fixturesFullPath}/bar.foo`, {\n envDetectors: [detector],\n });\n assert.deepEqual(result2, ['foo']);\n });\n\n describe('when given detective configuration', () => {\n // This test case doesn't fit the current implementation of precinct.\n it.skip('still does not filter out core module by default', () => {\n const stub = sinon.stub().returns([]);\n const revert = precinctNonWired.__set__('precinct', stub);\n\n precinct.paperwork(`${fixturesFullPath}/amd.js`, {\n amd: {\n skipLazyLoaded: true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AAQ,CAACQ,SAAS,CAAC,GAAGZ,gBAAgB,UAAU,EAAE;QAC/D6B,YAAY,EAAE,CAACR,QAAQ;MACzB,CAAC,CAAC;MACF3B,MAAM,CAAC0B,SAAS,CAACQ,MAAM,EAAE,EAAE,CAAC;MAE5B,MAAME,OAAO,GAAG1B,QAAQ,CAACQ,SAAS,CAAC,GAAGZ,gBAAgB,UAAU,EAAE;QAChE6B,YAAY,EAAE,CAACR,QAAQ;MACzB,CAAC,CAAC;MACF3B,MAAM,CAAC0B,SAAS,CAACU,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC;IAEFxB,QAAQ,CAAC,oCAAoC,EAAE,MAAM;MACnD;MACAC,EAAE,CAACC,IAAI,CAAC,kDAAkD,EAAE,MAAM;QAChE,MAAMuB,IAAI,GAAGjC,KAAK,CAACiC,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,EAAE,CAAC;QACrC,MAAMC,MAAM,GAAG9B,gBAAgB,CAAC+B,OAAO,CAAC,UAAU,EAAEH,IAAI,CAAC;QAEzD3B,QAAQ,CAACQ,SAAS,CAAC,GAAGZ,gBAAgB,SAAS,EAAE;UAC/CkB,GAAG,EAAE;YACHC,cAAc,EAAE;UAClB;QACF,CAAC,CAAC;QAEFzB,MAAM,CAACyC,KAAK,CAACJ,IAAI,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACpB,WAAW,EAAE,IAAI,CAAC;QAC/CiB,MAAM,CAAC,CAAC;MACV,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
@@ -3,6 +3,8 @@ export type FileContext = {
|
|
3
3
|
* extension of the file. (e.g. `.js`, '.jsx', '.ts', etc.)
|
4
4
|
*/
|
5
5
|
ext: string;
|
6
|
+
|
7
|
+
filename: string;
|
6
8
|
};
|
7
9
|
|
8
10
|
export type DependencyContext = {
|
@@ -51,18 +53,20 @@ export interface DependencyDetector {
|
|
51
53
|
export class DetectorHook {
|
52
54
|
static hooks: DependencyDetector[] = [];
|
53
55
|
|
54
|
-
isSupported(ext: string): boolean {
|
56
|
+
isSupported(ext: string, filename: string): boolean {
|
55
57
|
return !!DetectorHook.hooks.find((hook) => {
|
56
58
|
return hook.isSupported({
|
57
59
|
ext,
|
60
|
+
filename,
|
58
61
|
});
|
59
62
|
});
|
60
63
|
}
|
61
64
|
|
62
|
-
getDetector(ext: string): DependencyDetector | undefined {
|
65
|
+
getDetector(ext: string, filename: string): DependencyDetector | undefined {
|
63
66
|
return DetectorHook.hooks.find((hook) => {
|
64
67
|
return hook.isSupported({
|
65
68
|
ext,
|
69
|
+
filename,
|
66
70
|
});
|
67
71
|
});
|
68
72
|
}
|
@@ -58,7 +58,7 @@ export default function cabinet(options: Options) {
|
|
58
58
|
}
|
59
59
|
if (ext === '.css' && dependency.startsWith('~')) resolver = lookupStyling;
|
60
60
|
|
61
|
-
const detector = detectorHook.getDetector(ext);
|
61
|
+
const detector = detectorHook.getDetector(ext, filename);
|
62
62
|
if (detector) {
|
63
63
|
// test if the new detector API has a dependency lookup.
|
64
64
|
if (detector.dependencyLookup) {
|
@@ -71,7 +71,7 @@ export default function cabinet(options: Options) {
|
|
71
71
|
|
72
72
|
if (options?.envDetectors) {
|
73
73
|
for (const envDetector of options.envDetectors) {
|
74
|
-
if (envDetector.isSupported({ ext }) && envDetector.dependencyLookup) {
|
74
|
+
if (envDetector.isSupported({ ext, filename }) && envDetector.dependencyLookup) {
|
75
75
|
resolver = envDetector.dependencyLookup;
|
76
76
|
}
|
77
77
|
}
|
@@ -1,188 +1,17 @@
|
|
1
|
-
import { expect } from 'chai';
|
2
1
|
import { DependencyDetector } from '../detector-hook';
|
3
2
|
|
4
3
|
const assert = require('assert');
|
5
|
-
const fs = require('fs');
|
6
4
|
const path = require('path');
|
7
5
|
const rewire = require('rewire');
|
8
6
|
const sinon = require('sinon');
|
9
7
|
|
10
8
|
const fixtures = '../fixtures/precinct';
|
11
9
|
const fixturesFullPath = path.resolve(__dirname, fixtures);
|
12
|
-
const exampleASTPath = path.join(fixtures, 'exampleAST');
|
13
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
14
|
-
const ast = require(exampleASTPath);
|
15
10
|
|
16
11
|
const precinctNonWired = rewire('./');
|
17
12
|
const precinct = precinctNonWired.default;
|
18
13
|
|
19
|
-
function read(filename) {
|
20
|
-
return fs.readFileSync(path.join(fixturesFullPath, filename), 'utf8');
|
21
|
-
}
|
22
|
-
|
23
14
|
describe('node-precinct', () => {
|
24
|
-
it('accepts an AST', () => {
|
25
|
-
const deps = precinct(ast);
|
26
|
-
const depsKeys = Object.keys(deps);
|
27
|
-
assert(depsKeys.length === 1);
|
28
|
-
});
|
29
|
-
|
30
|
-
it('dangles off a given ast', () => {
|
31
|
-
precinct(ast);
|
32
|
-
assert.deepEqual(precinct.ast, ast);
|
33
|
-
});
|
34
|
-
|
35
|
-
it('dangles off the parsed ast from a .js file', () => {
|
36
|
-
precinct(read('amd.js'));
|
37
|
-
assert.ok(precinct.ast);
|
38
|
-
assert.notDeepEqual(precinct.ast, ast);
|
39
|
-
});
|
40
|
-
|
41
|
-
it('dangles off the parsed ast from a scss detective', () => {
|
42
|
-
precinct(read('styles.scss'), 'scss');
|
43
|
-
assert.notDeepEqual(precinct.ast, {});
|
44
|
-
});
|
45
|
-
|
46
|
-
it('dangles off the parsed ast from a sass detective', () => {
|
47
|
-
precinct(read('styles.sass'), 'sass');
|
48
|
-
assert.notDeepEqual(precinct.ast, {});
|
49
|
-
});
|
50
|
-
|
51
|
-
it('grabs dependencies of amd modules', () => {
|
52
|
-
const amd = precinct(read('amd.js'));
|
53
|
-
assert(amd.indexOf('./a') !== -1);
|
54
|
-
assert(amd.indexOf('./b') !== -1);
|
55
|
-
assert(amd.length === 2);
|
56
|
-
});
|
57
|
-
|
58
|
-
it('grabs dependencies of commonjs modules', () => {
|
59
|
-
const cjs = precinct(read('commonjs.js'));
|
60
|
-
expect(cjs).to.have.property('./a');
|
61
|
-
expect(cjs).to.have.property('./b');
|
62
|
-
assert(Object.keys(cjs).length === 2);
|
63
|
-
});
|
64
|
-
|
65
|
-
it('grabs dependencies of es6 modules', () => {
|
66
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
67
|
-
console.log(square(11)); // 121
|
68
|
-
console.log(diag(4, 3)); // 5`);
|
69
|
-
expect(cjs).to.have.property('lib');
|
70
|
-
assert(Object.keys(cjs).length === 1);
|
71
|
-
});
|
72
|
-
|
73
|
-
it('grabs dependencies of es6 modules with embedded jsx', () => {
|
74
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
75
|
-
const tmpl = <jsx />;`);
|
76
|
-
expect(cjs).to.have.property('lib');
|
77
|
-
assert(Object.keys(cjs).length === 1);
|
78
|
-
});
|
79
|
-
|
80
|
-
it('grabs dependencies of es6 modules with embedded es7', () => {
|
81
|
-
const cjs = precinct(`import { square, diag } from 'lib';
|
82
|
-
async function foo() {}`);
|
83
|
-
expect(cjs).to.have.property('lib');
|
84
|
-
assert(Object.keys(cjs).length === 1);
|
85
|
-
});
|
86
|
-
|
87
|
-
it('throws errors of es6 modules with syntax errors', () => {
|
88
|
-
const precinctFunc = () =>
|
89
|
-
precinct(`import { square, diag } from 'lib' // error, semicolon
|
90
|
-
console.log(square(11)); // 121
|
91
|
-
console.log(diag(4, 3); // 5, error, missing paren`);
|
92
|
-
expect(precinctFunc).to.throw();
|
93
|
-
});
|
94
|
-
|
95
|
-
// this is for supporting PostCSS dialect. The implementation is not merged to this project.
|
96
|
-
// see the following PR of node-precinct: https://github.com/dependents/node-precinct/pull/40
|
97
|
-
it.skip('grabs dependencies of css files', () => {
|
98
|
-
const css = precinct(read('styles.css'), 'css');
|
99
|
-
expect(css).to.have.property('foo.css');
|
100
|
-
expect(css).to.have.property('baz.css');
|
101
|
-
expect(css).to.have.property('bla.css');
|
102
|
-
expect(css).to.have.property('another.css');
|
103
|
-
});
|
104
|
-
|
105
|
-
it('grabs dependencies of scss files', function () {
|
106
|
-
const scss = precinct(read('styles.scss'), 'scss');
|
107
|
-
assert.deepEqual(scss, ['_foo', 'baz.scss']);
|
108
|
-
});
|
109
|
-
|
110
|
-
it('grabs dependencies of sass files', () => {
|
111
|
-
const sass = precinct(read('styles.sass'), 'sass');
|
112
|
-
assert.deepEqual(sass, ['_foo']);
|
113
|
-
});
|
114
|
-
|
115
|
-
it('grabs dependencies of stylus files', () => {
|
116
|
-
const result = precinct(read('styles.styl'), 'stylus');
|
117
|
-
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
118
|
-
|
119
|
-
assert.deepEqual(result, expected);
|
120
|
-
});
|
121
|
-
|
122
|
-
it('grabs dependencies of less files', () => {
|
123
|
-
const result = precinct(read('styles.less'), 'less');
|
124
|
-
const expected = ['_foo', '_bar.css', 'baz.less'];
|
125
|
-
|
126
|
-
assert.deepEqual(result, expected);
|
127
|
-
});
|
128
|
-
// todo: fix this one once we have a way to ignore some component files from compiling/parsing altogether
|
129
|
-
// uncomment typescript.ts
|
130
|
-
it.skip('grabs dependencies of typescript files', () => {
|
131
|
-
const result = precinct(read('typescript.ts'), 'ts');
|
132
|
-
const expected = ['fs', 'lib', './bar', './my-module.js', './ZipCodeValidator'];
|
133
|
-
|
134
|
-
assert.deepEqual(Object.keys(result), expected);
|
135
|
-
});
|
136
|
-
|
137
|
-
it('throws errors of typescript modules with syntax errors', () => {
|
138
|
-
const precinctFunc = () =>
|
139
|
-
precinct(`import { square, diag } from 'lib';
|
140
|
-
console.log(diag(4, 3); // error, missing bracket
|
141
|
-
`);
|
142
|
-
expect(precinctFunc).to.throw();
|
143
|
-
});
|
144
|
-
|
145
|
-
it('supports the object form of type configuration', () => {
|
146
|
-
const result = precinct(read('styles.styl'), { type: 'stylus' });
|
147
|
-
const expected = ['mystyles', 'styles2.styl', 'styles3.styl', 'styles4'];
|
148
|
-
|
149
|
-
assert.deepEqual(result, expected);
|
150
|
-
});
|
151
|
-
|
152
|
-
it('yields no dependencies for es6 modules with no imports', () => {
|
153
|
-
const cjs = precinct(`export const sqrt = Math.sqrt;
|
154
|
-
export function square(x) {
|
155
|
-
return x * x;
|
156
|
-
}
|
157
|
-
export function diag(x, y) {
|
158
|
-
return sqrt(square(x) + square(y));
|
159
|
-
}
|
160
|
-
`);
|
161
|
-
assert.equal(Object.keys(cjs).length, 0);
|
162
|
-
});
|
163
|
-
|
164
|
-
it('yields no dependencies for non-modules', () => {
|
165
|
-
const none = precinct(`var a = new window.Foo();`);
|
166
|
-
assert.equal(Object.keys(none).length, 0);
|
167
|
-
});
|
168
|
-
|
169
|
-
it('throw on unparsable .js files', () => {
|
170
|
-
assert.throws(() => {
|
171
|
-
precinct(`{
|
172
|
-
"very invalid": "javascript",
|
173
|
-
"this", "is actually json",
|
174
|
-
"But" not even valid json.
|
175
|
-
}
|
176
|
-
`);
|
177
|
-
}, SyntaxError);
|
178
|
-
});
|
179
|
-
|
180
|
-
it('does not blow up when parsing a gruntfile #2', () => {
|
181
|
-
assert.doesNotThrow(() => {
|
182
|
-
precinct(read('Gruntfile.js'));
|
183
|
-
});
|
184
|
-
});
|
185
|
-
|
186
15
|
describe('paperwork', () => {
|
187
16
|
// todo: currently it doesn't work because we set it with bit-no-check
|
188
17
|
it.skip('returns the dependencies for the given filepath', () => {
|
@@ -266,77 +95,4 @@ export function diag(x, y) {
|
|
266
95
|
});
|
267
96
|
});
|
268
97
|
});
|
269
|
-
|
270
|
-
describe('when given a configuration object', () => {
|
271
|
-
it('passes amd config to the amd detective', () => {
|
272
|
-
const config = {
|
273
|
-
amd: {
|
274
|
-
skipLazyLoaded: true,
|
275
|
-
},
|
276
|
-
};
|
277
|
-
|
278
|
-
const deps = precinct(read('amd.js'), config);
|
279
|
-
assert.deepEqual(deps, ['./a', './b']);
|
280
|
-
});
|
281
|
-
|
282
|
-
describe('that sets mixedImports for es6', () => {
|
283
|
-
describe('for a file identified as es6', () => {
|
284
|
-
it('returns both the commonjs and es6 dependencies', () => {
|
285
|
-
const deps = precinct(
|
286
|
-
`import foo from './foo';
|
287
|
-
var bar = require('./bar');`,
|
288
|
-
{
|
289
|
-
es6: {
|
290
|
-
mixedImports: true,
|
291
|
-
},
|
292
|
-
}
|
293
|
-
);
|
294
|
-
|
295
|
-
assert.equal(Object.keys(deps).length, 2);
|
296
|
-
});
|
297
|
-
});
|
298
|
-
|
299
|
-
describe('for a file identified as cjs', () => {
|
300
|
-
it('returns both the commonjs and es6 dependencies', () => {
|
301
|
-
const deps = precinct(
|
302
|
-
`var bar = require('./bar');
|
303
|
-
import foo from './foo';`,
|
304
|
-
{
|
305
|
-
es6: {
|
306
|
-
mixedImports: true,
|
307
|
-
},
|
308
|
-
}
|
309
|
-
);
|
310
|
-
|
311
|
-
assert.equal(Object.keys(deps).length, 2);
|
312
|
-
});
|
313
|
-
});
|
314
|
-
});
|
315
|
-
});
|
316
|
-
|
317
|
-
describe('when lazy exported dependencies in CJS', () => {
|
318
|
-
it('grabs those lazy dependencies', () => {
|
319
|
-
const cjs = precinct(read('cjsExportLazy.js'));
|
320
|
-
expect(cjs).to.have.property('./amd');
|
321
|
-
expect(cjs).to.have.property('./es6');
|
322
|
-
expect(cjs).to.have.property('./es7');
|
323
|
-
assert.equal(Object.keys(cjs).length, 3);
|
324
|
-
});
|
325
|
-
});
|
326
|
-
|
327
|
-
describe('when given an es6 file', () => {
|
328
|
-
describe('that uses CJS imports for lazy dependencies', () => {
|
329
|
-
it('grabs the lazy imports', () => {
|
330
|
-
const es6 = precinct(read('es6MixedExportLazy.js'), {
|
331
|
-
es6: {
|
332
|
-
mixedImports: true,
|
333
|
-
},
|
334
|
-
});
|
335
|
-
expect(es6).to.have.property('./amd');
|
336
|
-
expect(es6).to.have.property('./es6');
|
337
|
-
expect(es6).to.have.property('./es7');
|
338
|
-
assert.equal(Object.keys(es6).length, 3);
|
339
|
-
});
|
340
|
-
});
|
341
|
-
});
|
342
98
|
});
|