diff --git a/eslint.config.mjs b/eslint.config.mjs index 624def4..b18276b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -11,8 +11,8 @@ export default typegen(antfu({ }, [ { ignores: [ - 'test/**/*.vue', - 'test/**/*.jsx', + 'fixtures/**/*', + 'test/output/**/*', 'public/**/*', 'components/ui/**/*', ], diff --git a/test/tsx/TestComponent3.jsx b/fixtures/react/tsx3.jsx similarity index 100% rename from test/tsx/TestComponent3.jsx rename to fixtures/react/tsx3.jsx diff --git a/test/tsx/TestComponent4.jsx b/fixtures/react/tsx4.jsx similarity index 100% rename from test/tsx/TestComponent4.jsx rename to fixtures/react/tsx4.jsx diff --git a/test/options-base-defineComponent/TestComponent.vue b/fixtures/vue/options-base-defineComponent.vue similarity index 100% rename from test/options-base-defineComponent/TestComponent.vue rename to fixtures/vue/options-base-defineComponent.vue diff --git a/test/options-base-jsx/TestComponent.vue b/fixtures/vue/options-base-jsx.vue similarity index 100% rename from test/options-base-jsx/TestComponent.vue rename to fixtures/vue/options-base-jsx.vue diff --git a/test/options-base/TestComponent.vue b/fixtures/vue/options-base.vue similarity index 100% rename from test/options-base/TestComponent.vue rename to fixtures/vue/options-base.vue diff --git a/test/options-setup-jsx/TestComponent.vue b/fixtures/vue/options-setup-jsx.vue similarity index 100% rename from test/options-setup-jsx/TestComponent.vue rename to fixtures/vue/options-setup-jsx.vue diff --git a/test/options-setup/TestComponent.vue b/fixtures/vue/options-setup.vue similarity index 100% rename from test/options-setup/TestComponent.vue rename to fixtures/vue/options-setup.vue diff --git a/test/setup-block/TestComponent.vue b/fixtures/vue/setup-block.vue similarity index 99% rename from test/setup-block/TestComponent.vue rename to fixtures/vue/setup-block.vue index d4333c9..365e1d0 100644 --- a/test/setup-block/TestComponent.vue +++ b/fixtures/vue/setup-block.vue @@ -53,7 +53,7 @@ function funC(varB) { // 这是注释 const [ varD, varE ] = funC(varB) onMounted(() => { - funC() + funC?.() }) const props1 = withDefaults(defineProps<{test: number}>(), { diff --git a/test/tsx/TestComponent.vue b/fixtures/vue/tsx1.vue similarity index 100% rename from test/tsx/TestComponent.vue rename to fixtures/vue/tsx1.vue diff --git a/test/tsx/TestComponent2.vue b/fixtures/vue/tsx2.vue similarity index 100% rename from test/tsx/TestComponent2.vue rename to fixtures/vue/tsx2.vue diff --git a/package.json b/package.json index da132e1..3f92cef 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "eslint-plugin-security": "^3.0.1", "eslint-plugin-vue-hook-optimizer": "workspace:*", "eslint-typegen": "^0.2.4", + "fast-glob": "^3.3.2", "lodash-es": "^4.17.21", "nodemon": "^3.1.0", "ts-node": "^10.9.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6faf9b8..2dca438 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,9 @@ importers: eslint-typegen: specifier: ^0.2.4 version: 0.2.4(eslint@9.6.0) + fast-glob: + specifier: ^3.3.2 + version: 3.3.2 lodash-es: specifier: ^4.17.21 version: 4.17.21 @@ -3548,10 +3551,6 @@ packages: fast-fifo@1.3.2: resolution: {integrity: sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==} - fast-glob@3.3.1: - resolution: {integrity: sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==} - engines: {node: '>=8.6.0'} - fast-glob@3.3.2: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} @@ -10792,14 +10791,6 @@ snapshots: fast-fifo@1.3.2: {} - fast-glob@3.3.1: - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.5 - fast-glob@3.3.2: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -11051,7 +11042,7 @@ snapshots: dependencies: array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.3.1 + fast-glob: 3.3.2 ignore: 5.3.1 merge2: 1.4.1 slash: 3.0.0 @@ -11059,7 +11050,7 @@ snapshots: globby@13.2.2: dependencies: dir-glob: 3.0.1 - fast-glob: 3.3.1 + fast-glob: 3.3.2 ignore: 5.2.4 merge2: 1.4.1 slash: 4.0.0 diff --git a/test/fixtures.test.ts b/test/fixtures.test.ts new file mode 100644 index 0000000..b7c8b33 --- /dev/null +++ b/test/fixtures.test.ts @@ -0,0 +1,79 @@ +import { readFileSync } from 'node:fs'; +import { basename } from 'node:path'; +import fg from 'fast-glob'; +import { analyzeOptions, analyzeSetupScript, analyzeTemplate, analyzeTsx, parse } from '@/index'; + +describe('fixtures', async () => { + const frameworks = ['vue', 'react'] as const; + for (const framework of frameworks) { + const tests = await fg(`./fixtures/${framework}/**/*`); + for (const test of tests) { + const testName = `${framework}/${basename(test)}`; + it(testName, async () => { + const source = readFileSync(test, 'utf-8'); + if (framework === 'vue') { + const sfc = parse(source); + if (test.includes('tsx')) { + const { graph, nodesUsedInTemplate } = analyzeTsx( + sfc.descriptor.script?.content || '', + 'vue', + (sfc.descriptor.script?.loc.start.line || 1) - 1, + ); + + await expect(graph) + .toMatchFileSnapshot(`./output/${testName}.graph.txt`); + + const nodes = sfc.descriptor.template?.content + ? analyzeTemplate(sfc.descriptor.template!.content) + : new Set(); + + await expect(new Set([...nodesUsedInTemplate, ...nodes])) + .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); + } + else if (sfc.descriptor.scriptSetup?.content) { + const graph = analyzeSetupScript( + sfc.descriptor.scriptSetup?.content || '', + (sfc.descriptor.scriptSetup?.loc.start.line || 1) - 1, + ); + await expect(graph) + .toMatchFileSnapshot(`./output/${testName}.graph.txt`); + + const nodes = sfc.descriptor.template?.content + ? analyzeTemplate(sfc.descriptor.template!.content) + : new Set(); + await expect(nodes) + .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); + } + else { + const { graph, nodesUsedInTemplate } = analyzeOptions( + sfc.descriptor.script?.content || '', + (sfc.descriptor.script?.loc.start.line || 1) - 1, + true, + ); + await expect(graph) + .toMatchFileSnapshot(`./output/${testName}.graph.txt`); + + const nodes = sfc.descriptor.template?.content + ? analyzeTemplate(sfc.descriptor.template!.content) + : new Set(); + + await expect(new Set([...nodesUsedInTemplate, ...nodes])) + .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); + } + } + if (framework === 'react') { + const { graph, nodesUsedInTemplate } = analyzeTsx( + source, + 'react', + 0, + ); + await expect(graph) + .toMatchFileSnapshot(`./output/${testName}.graph.txt`); + + await expect(nodesUsedInTemplate) + .toMatchFileSnapshot(`./output/${testName}.nodes.txt`); + } + }); + } + } +}); diff --git a/test/options-base-defineComponent/TestComponent.graph.ts b/test/options-base-defineComponent/TestComponent.graph.ts deleted file mode 100644 index 3ed0636..0000000 --- a/test/options-base-defineComponent/TestComponent.graph.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const number: TypedNode = { label: 'number', type: NodeType.var, info: { line: 65, column: 8 } }; -const count: TypedNode = { label: 'count', type: NodeType.var, info: { line: 69, column: 6 } }; -const double: TypedNode = { label: 'double', type: NodeType.var, info: { line: 72, column: 6 } }; -const plus: TypedNode = { label: 'plus', type: NodeType.fun, info: { line: 82, column: 6 } }; -const add: TypedNode = { label: 'add', type: NodeType.fun, info: { line: 86, column: 6 } }; - -edges.set(number, new Set([])); -edges.set(count, new Set([number])); -edges.set(double, new Set([number])); -edges.set(plus, new Set([plus])); -edges.set(add, new Set([number, add])); - -export const graph = { - nodes: new Set([number, count, double, plus, add]), - edges, -}; diff --git a/test/options-base-defineComponent/TestComponent.nodes.ts b/test/options-base-defineComponent/TestComponent.nodes.ts deleted file mode 100644 index ea2214f..0000000 --- a/test/options-base-defineComponent/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['msg', 'plus', 'count', 'number', 'add']); diff --git a/test/options-base-defineComponent/index.test.ts b/test/options-base-defineComponent/index.test.ts deleted file mode 100644 index e103dcf..0000000 --- a/test/options-base-defineComponent/index.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeOptions, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze options base', () => { - const { graph } = analyzeOptions( - sfc.descriptor.script?.content || '', - (sfc.descriptor.script?.loc.start.line || 1) - 1, - ); - expect(graph).toEqual(graphRes); - }); - it('test analyze template', () => { - const nodes = analyzeTemplate(sfc.descriptor.template!.content); - expect(nodes).toEqual(nodesRes); - }); -}); diff --git a/test/options-base-jsx/TestComponent.graph.ts b/test/options-base-jsx/TestComponent.graph.ts deleted file mode 100644 index 4eee0d4..0000000 --- a/test/options-base-jsx/TestComponent.graph.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const number: TypedNode = { label: 'number', type: NodeType.var, info: { line: 11, column: 8 } }; -const count: TypedNode = { label: 'count', type: NodeType.var, info: { line: 15, column: 6, used: new Set(['provide']) } }; -const plus: TypedNode = { label: 'plus', type: NodeType.fun, info: { line: 20, column: 6 } }; -const add: TypedNode = { label: 'add', type: NodeType.fun, info: { line: 24, column: 6 } }; - -edges.set(number, new Set([])); -edges.set(count, new Set([])); -edges.set(plus, new Set([plus])); -edges.set(add, new Set([number, add])); - -export const graph = { - nodes: new Set([number, count, plus, add]), - edges, -}; diff --git a/test/options-base-jsx/TestComponent.nodes.ts b/test/options-base-jsx/TestComponent.nodes.ts deleted file mode 100644 index e91921b..0000000 --- a/test/options-base-jsx/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['count', 'plus']); diff --git a/test/options-base-jsx/index.test.ts b/test/options-base-jsx/index.test.ts deleted file mode 100644 index 14b94c6..0000000 --- a/test/options-base-jsx/index.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeOptions, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze options base', () => { - const { graph, nodesUsedInTemplate } = analyzeOptions( - sfc.descriptor.script?.content || '', - (sfc.descriptor.script?.loc.start.line || 1) - 1, - true, - ); - expect(graph).toEqual(graphRes); - expect(nodesUsedInTemplate).toEqual(nodesRes); - }); -}); diff --git a/test/options-base/TestComponent.graph.ts b/test/options-base/TestComponent.graph.ts deleted file mode 100644 index 0d848be..0000000 --- a/test/options-base/TestComponent.graph.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const number: TypedNode = { label: 'number', type: NodeType.var, info: { line: 65, column: 8 } }; -const count: TypedNode = { label: 'count', type: NodeType.var, info: { line: 69, column: 6, used: new Set(['watch', 'created']) } }; -const plus: TypedNode = { label: 'plus', type: NodeType.fun, info: { line: 74, column: 6 } }; -const add: TypedNode = { label: 'add', type: NodeType.fun, info: { line: 78, column: 6 } }; - -edges.set(number, new Set([])); -edges.set(count, new Set([number])); -edges.set(plus, new Set([plus])); -edges.set(add, new Set([number, add])); - -export const graph = { - nodes: new Set([number, count, plus, add]), - edges, -}; diff --git a/test/options-base/TestComponent.nodes.ts b/test/options-base/TestComponent.nodes.ts deleted file mode 100644 index ea2214f..0000000 --- a/test/options-base/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['msg', 'plus', 'count', 'number', 'add']); diff --git a/test/options-base/index.test.ts b/test/options-base/index.test.ts deleted file mode 100644 index 48275a9..0000000 --- a/test/options-base/index.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeOptions, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze options base', () => { - const { graph } = analyzeOptions(sfc.descriptor.script?.content || '', (sfc.descriptor.script?.loc.start.line || 1) - 1); - expect(graph).toEqual(graphRes); - }); - it('test analyze template', () => { - const nodes = analyzeTemplate(sfc.descriptor.template!.content); - expect(nodes).toEqual(nodesRes); - }); -}); diff --git a/test/options-setup-jsx/TestComponent.graph.ts b/test/options-setup-jsx/TestComponent.graph.ts deleted file mode 100644 index 1409f83..0000000 --- a/test/options-setup-jsx/TestComponent.graph.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const data: TypedNode = { label: 'data', type: NodeType.var, info: { line: 10, column: 10 } }; -const count: TypedNode = { label: 'count', type: NodeType.var, info: { line: 13, column: 10 } }; -const methods: TypedNode = { label: 'methods', type: NodeType.var, info: { line: 15, column: 10 } }; - -const a: TypedNode = { label: 'a', type: NodeType.var, info: { line: 27, column: 10 } }; -const b: TypedNode = { label: 'b', type: NodeType.var, info: { line: 28, column: 10 } }; -const ComponentD: TypedNode = { label: 'ComponentD', type: NodeType.fun, info: { line: 29, column: 10 } }; -const msgRef: TypedNode = { label: 'msgRef', type: NodeType.var, info: { line: 31, column: 10 } }; - -edges.set(data, new Set([])); -edges.set(count, new Set([])); -edges.set(methods, new Set([methods, data, count])); -edges.set(a, new Set([count])); -edges.set(b, new Set([count])); -edges.set(ComponentD, new Set([])); -// edges.set(a, new Set([count])); -edges.set(msgRef, new Set([])); - -export const graph = { - nodes: new Set([data, count, methods, a, b, ComponentD, msgRef]), - edges, -}; diff --git a/test/options-setup-jsx/TestComponent.nodes.ts b/test/options-setup-jsx/TestComponent.nodes.ts deleted file mode 100644 index dbee1d8..0000000 --- a/test/options-setup-jsx/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['count', 'methods', 'ComponentD']); diff --git a/test/options-setup-jsx/index.test.ts b/test/options-setup-jsx/index.test.ts deleted file mode 100644 index 298355b..0000000 --- a/test/options-setup-jsx/index.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeOptions, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze options setup', () => { - const { graph, nodesUsedInTemplate } = analyzeOptions( - sfc.descriptor.script?.content || '', - (sfc.descriptor.script?.loc.start.line || 1) - 1, - true, - ); - expect(graph).toEqual(graphRes); - expect(nodesUsedInTemplate).toEqual(nodesRes); - }); -}); diff --git a/test/options-setup/TestComponent.graph.ts b/test/options-setup/TestComponent.graph.ts deleted file mode 100644 index ae3e8f5..0000000 --- a/test/options-setup/TestComponent.graph.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const number: TypedNode = { label: 'number', type: NodeType.var, info: { line: 66, column: 17, comment: '这是注释' } }; -const count: TypedNode = { label: 'count', type: NodeType.var, info: { line: 68, column: 10 } }; -const plus: TypedNode = { label: 'plus', type: NodeType.fun, info: { line: 71, column: 6 } }; -const add: TypedNode = { label: 'add', type: NodeType.fun, info: { line: 75, column: 6 } }; -// const a: TypedNode = {label: 'a', type: NodeType.var, info: {line: 82, column: 10}}; -const b: TypedNode = { label: 'b', type: NodeType.var, info: { line: 83, column: 10 } }; -const c: TypedNode = { label: 'c', type: NodeType.var, info: { line: 91, column: 6 } }; -const ComponentD: TypedNode = { label: 'ComponentD', type: NodeType.fun, info: { line: 84, column: 10 } }; -const msgRef: TypedNode = { label: 'msgRef', type: NodeType.var, info: { line: 86, column: 10 } }; - -edges.set(number, new Set([])); -edges.set(b, new Set([count])); -edges.set(count, new Set([])); -edges.set(c, new Set([count])); -edges.set(plus, new Set([plus])); -edges.set(add, new Set([number, add, count])); -edges.set(ComponentD, new Set([])); -// edges.set(a, new Set([count])); -edges.set(msgRef, new Set([])); - -export const graph = { - nodes: new Set([number, b, count, c, plus, add, ComponentD, msgRef]), - edges, -}; diff --git a/test/options-setup/TestComponent.nodes.ts b/test/options-setup/TestComponent.nodes.ts deleted file mode 100644 index 76a48dc..0000000 --- a/test/options-setup/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['msg', 'plus', 'count', 'number', 'add', 'ComponentD', 'msgRef']); diff --git a/test/options-setup/index.test.ts b/test/options-setup/index.test.ts deleted file mode 100644 index a20f974..0000000 --- a/test/options-setup/index.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeOptions, analyzeStyle, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze options setup', () => { - const { graph } = analyzeOptions( - sfc.descriptor.script?.content || '', - (sfc.descriptor.script?.loc.start.line || 1) - 1, - true, - ); - expect(graph).toEqual(graphRes); - }); - it('test analyze template', () => { - const nodes = analyzeTemplate(sfc.descriptor.template!.content); - expect(nodes).toEqual(nodesRes); - }); - it('test analyze style', () => { - const nodes = analyzeStyle(sfc.descriptor.styles); - expect(nodes).toMatchInlineSnapshot(` - Set { - "count", - } - `); - }); -}); diff --git a/test/output/react/tsx3.jsx.graph.txt b/test/output/react/tsx3.jsx.graph.txt new file mode 100644 index 0000000..ba2c616 --- /dev/null +++ b/test/output/react/tsx3.jsx.graph.txt @@ -0,0 +1,363 @@ +{ + "edges": Map { + { + "info": { + "column": 12, + "line": 59, + }, + "label": "store", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 61, + }, + "label": "configLoaded", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 62, + }, + "label": "config", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 63, + }, + "label": "terminalFullScreen", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 64, + }, + "label": "pinned", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 65, + }, + "label": "isSencondInstance", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 66, + }, + "label": "pinnedQuickCommandBar", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 67, + }, + "label": "wsInited", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 68, + }, + "label": "upgradeInfo", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 69, + }, + "label": "installSrc", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 70, + }, + "label": "uiThemeConfig", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 72, + }, + "label": "cls", + "type": "var", + } => Set { + { + "info": { + "column": 6, + "line": 61, + }, + "label": "configLoaded", + "type": "var", + }, + { + "info": { + "column": 12, + "line": 59, + }, + "label": "store", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 64, + }, + "label": "pinned", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 66, + }, + "label": "pinnedQuickCommandBar", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 63, + }, + "label": "terminalFullScreen", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 65, + }, + "label": "isSencondInstance", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 82, + }, + "label": "ext1", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 72, + }, + "label": "cls", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 85, + }, + "label": "cpConf", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 86, + }, + "label": "confsCss", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 85, + }, + "label": "cpConf", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 95, + }, + "label": "themeProps", + "type": "var", + } => Set { + { + "info": { + "column": 12, + "line": 59, + }, + "label": "store", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 98, + }, + "label": "outerProps", + "type": "var", + } => Set { + { + "info": { + "column": 6, + "line": 62, + }, + "label": "config", + "type": "var", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 12, + "line": 59, + }, + "label": "store", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 61, + }, + "label": "configLoaded", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 62, + }, + "label": "config", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 63, + }, + "label": "terminalFullScreen", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 64, + }, + "label": "pinned", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 65, + }, + "label": "isSencondInstance", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 66, + }, + "label": "pinnedQuickCommandBar", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 67, + }, + "label": "wsInited", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 68, + }, + "label": "upgradeInfo", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 69, + }, + "label": "installSrc", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 70, + }, + "label": "uiThemeConfig", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 72, + }, + "label": "cls", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 82, + }, + "label": "ext1", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 85, + }, + "label": "cpConf", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 86, + }, + "label": "confsCss", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 95, + }, + "label": "themeProps", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 98, + }, + "label": "outerProps", + "type": "var", + }, + }, +} \ No newline at end of file diff --git a/test/output/react/tsx3.jsx.nodes.txt b/test/output/react/tsx3.jsx.nodes.txt new file mode 100644 index 0000000..96a802f --- /dev/null +++ b/test/output/react/tsx3.jsx.nodes.txt @@ -0,0 +1,13 @@ +Set { + "uiThemeConfig", + "ext1", + "wsInited", + "terminalFullScreen", + "confsCss", + "themeProps", + "store", + "cpConf", + "upgradeInfo", + "installSrc", + "outerProps", +} \ No newline at end of file diff --git a/test/output/react/tsx4.jsx.graph.txt b/test/output/react/tsx4.jsx.graph.txt new file mode 100644 index 0000000..a36f238 --- /dev/null +++ b/test/output/react/tsx4.jsx.graph.txt @@ -0,0 +1,104 @@ +{ + "edges": Map { + { + "info": { + "column": 9, + "line": 1, + }, + "label": "open", + "type": "var", + } => Set {}, + { + "info": { + "column": 15, + "line": 1, + }, + "label": "setOpen", + "type": "var", + } => Set {}, + { + "info": { + "column": 9, + "line": 3, + }, + "label": "xx", + "type": "var", + } => Set {}, + { + "info": { + "column": 2, + "line": 5, + }, + "label": "processInfo", + "type": "fun", + } => Set { + { + "info": { + "column": 9, + "line": 1, + }, + "label": "open", + "type": "var", + }, + }, + { + "info": { + "column": 8, + "line": 9, + }, + "label": "writeBaseInfo", + "type": "fun", + } => Set { + { + "info": { + "column": 9, + "line": 3, + }, + "label": "xx", + "type": "var", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 9, + "line": 1, + }, + "label": "open", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 1, + }, + "label": "setOpen", + "type": "var", + }, + { + "info": { + "column": 9, + "line": 3, + }, + "label": "xx", + "type": "var", + }, + { + "info": { + "column": 2, + "line": 5, + }, + "label": "processInfo", + "type": "fun", + }, + { + "info": { + "column": 8, + "line": 9, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + }, +} \ No newline at end of file diff --git a/test/output/react/tsx4.jsx.nodes.txt b/test/output/react/tsx4.jsx.nodes.txt new file mode 100644 index 0000000..495b3dc --- /dev/null +++ b/test/output/react/tsx4.jsx.nodes.txt @@ -0,0 +1,7 @@ +Set { + "open", + "writeBaseInfo", + "processInfo", + "setOpen", + "xx", +} \ No newline at end of file diff --git a/test/output/vue/options-base-defineComponent.vue.graph.txt b/test/output/vue/options-base-defineComponent.vue.graph.txt new file mode 100644 index 0000000..e3e9656 --- /dev/null +++ b/test/output/vue/options-base-defineComponent.vue.graph.txt @@ -0,0 +1,130 @@ +{ + "edges": Map { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 69, + }, + "label": "count", + "type": "var", + } => Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 72, + }, + "label": "double", + "type": "var", + } => Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 82, + }, + "label": "plus", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "line": 82, + }, + "label": "plus", + "type": "fun", + }, + }, + { + "info": { + "column": 6, + "line": 86, + }, + "label": "add", + "type": "fun", + } => Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 86, + }, + "label": "add", + "type": "fun", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 69, + }, + "label": "count", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 72, + }, + "label": "double", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 82, + }, + "label": "plus", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 86, + }, + "label": "add", + "type": "fun", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/options-base-defineComponent.vue.nodes.txt b/test/output/vue/options-base-defineComponent.vue.nodes.txt new file mode 100644 index 0000000..9513b55 --- /dev/null +++ b/test/output/vue/options-base-defineComponent.vue.nodes.txt @@ -0,0 +1,7 @@ +Set { + "msg", + "plus", + "count", + "number", + "add", +} \ No newline at end of file diff --git a/test/output/vue/options-base-jsx.vue.graph.txt b/test/output/vue/options-base-jsx.vue.graph.txt new file mode 100644 index 0000000..4a59e2f --- /dev/null +++ b/test/output/vue/options-base-jsx.vue.graph.txt @@ -0,0 +1,102 @@ +{ + "edges": Map { + { + "info": { + "column": 8, + "line": 11, + }, + "label": "number", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 15, + "used": Set { + "provide", + }, + }, + "label": "count", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 20, + }, + "label": "plus", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "line": 20, + }, + "label": "plus", + "type": "fun", + }, + }, + { + "info": { + "column": 6, + "line": 24, + }, + "label": "add", + "type": "fun", + } => Set { + { + "info": { + "column": 8, + "line": 11, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 24, + }, + "label": "add", + "type": "fun", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 8, + "line": 11, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 15, + "used": Set { + "provide", + }, + }, + "label": "count", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 20, + }, + "label": "plus", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 24, + }, + "label": "add", + "type": "fun", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/options-base-jsx.vue.nodes.txt b/test/output/vue/options-base-jsx.vue.nodes.txt new file mode 100644 index 0000000..2597686 --- /dev/null +++ b/test/output/vue/options-base-jsx.vue.nodes.txt @@ -0,0 +1,4 @@ +Set { + "count", + "plus", +} \ No newline at end of file diff --git a/test/output/vue/options-base.vue.graph.txt b/test/output/vue/options-base.vue.graph.txt new file mode 100644 index 0000000..1b126db --- /dev/null +++ b/test/output/vue/options-base.vue.graph.txt @@ -0,0 +1,113 @@ +{ + "edges": Map { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 69, + "used": Set { + "watch", + "created", + }, + }, + "label": "count", + "type": "var", + } => Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 74, + }, + "label": "plus", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "line": 74, + }, + "label": "plus", + "type": "fun", + }, + }, + { + "info": { + "column": 6, + "line": 78, + }, + "label": "add", + "type": "fun", + } => Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 78, + }, + "label": "add", + "type": "fun", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 8, + "line": 65, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 69, + "used": Set { + "watch", + "created", + }, + }, + "label": "count", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 74, + }, + "label": "plus", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 78, + }, + "label": "add", + "type": "fun", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/options-base.vue.nodes.txt b/test/output/vue/options-base.vue.nodes.txt new file mode 100644 index 0000000..9513b55 --- /dev/null +++ b/test/output/vue/options-base.vue.nodes.txt @@ -0,0 +1,7 @@ +Set { + "msg", + "plus", + "count", + "number", + "add", +} \ No newline at end of file diff --git a/test/output/vue/options-setup-jsx.vue.graph.txt b/test/output/vue/options-setup-jsx.vue.graph.txt new file mode 100644 index 0000000..5e8ffe5 --- /dev/null +++ b/test/output/vue/options-setup-jsx.vue.graph.txt @@ -0,0 +1,161 @@ +{ + "edges": Map { + { + "info": { + "column": 10, + "line": 10, + }, + "label": "data", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 13, + }, + "label": "count", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 15, + }, + "label": "methods", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 15, + }, + "label": "methods", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 10, + }, + "label": "data", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 13, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 27, + }, + "label": "a", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 13, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 28, + }, + "label": "b", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 13, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 29, + }, + "label": "ComponentD", + "type": "fun", + } => Set {}, + { + "info": { + "column": 10, + "line": 31, + }, + "label": "msgRef", + "type": "var", + } => Set {}, + }, + "nodes": Set { + { + "info": { + "column": 10, + "line": 10, + }, + "label": "data", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 13, + }, + "label": "count", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 15, + }, + "label": "methods", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 27, + }, + "label": "a", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 28, + }, + "label": "b", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 29, + }, + "label": "ComponentD", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 31, + }, + "label": "msgRef", + "type": "var", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/options-setup-jsx.vue.nodes.txt b/test/output/vue/options-setup-jsx.vue.nodes.txt new file mode 100644 index 0000000..582f642 --- /dev/null +++ b/test/output/vue/options-setup-jsx.vue.nodes.txt @@ -0,0 +1,5 @@ +Set { + "count", + "methods", + "ComponentD", +} \ No newline at end of file diff --git a/test/output/vue/options-setup.vue.graph.txt b/test/output/vue/options-setup.vue.graph.txt new file mode 100644 index 0000000..1c09b18 --- /dev/null +++ b/test/output/vue/options-setup.vue.graph.txt @@ -0,0 +1,189 @@ +{ + "edges": Map { + { + "info": { + "column": 17, + "comment": "这是注释", + "line": 66, + }, + "label": "number", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 83, + }, + "label": "b", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 68, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 68, + }, + "label": "count", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 91, + }, + "label": "c", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 68, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 71, + }, + "label": "plus", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "line": 71, + }, + "label": "plus", + "type": "fun", + }, + }, + { + "info": { + "column": 6, + "line": 75, + }, + "label": "add", + "type": "fun", + } => Set { + { + "info": { + "column": 17, + "comment": "这是注释", + "line": 66, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 75, + }, + "label": "add", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 68, + }, + "label": "count", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 84, + }, + "label": "ComponentD", + "type": "fun", + } => Set {}, + { + "info": { + "column": 10, + "line": 86, + }, + "label": "msgRef", + "type": "var", + } => Set {}, + }, + "nodes": Set { + { + "info": { + "column": 17, + "comment": "这是注释", + "line": 66, + }, + "label": "number", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 83, + }, + "label": "b", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 68, + }, + "label": "count", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 91, + }, + "label": "c", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 71, + }, + "label": "plus", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 75, + }, + "label": "add", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 84, + }, + "label": "ComponentD", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 86, + }, + "label": "msgRef", + "type": "var", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/options-setup.vue.nodes.txt b/test/output/vue/options-setup.vue.nodes.txt new file mode 100644 index 0000000..33e0124 --- /dev/null +++ b/test/output/vue/options-setup.vue.nodes.txt @@ -0,0 +1,9 @@ +Set { + "ComponentD", + "msgRef", + "msg", + "plus", + "count", + "number", + "add", +} \ No newline at end of file diff --git a/test/output/vue/setup-block.vue.graph.txt b/test/output/vue/setup-block.vue.graph.txt new file mode 100644 index 0000000..daa3f5d --- /dev/null +++ b/test/output/vue/setup-block.vue.graph.txt @@ -0,0 +1,367 @@ +{ + "edges": Map { + { + "info": { + "column": 6, + "comment": "route", + "line": 7, + }, + "label": "route", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "comment": "path", + "line": 9, + "used": Set { + "watch", + }, + }, + "label": "path", + "type": "var", + } => Set { + { + "info": { + "column": 6, + "comment": "route", + "line": 7, + }, + "label": "route", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 11, + "used": Set { + "watch", + }, + }, + "label": "lmsg", + "type": "var", + } => Set { + { + "info": { + "column": 6, + "comment": "path", + "line": 9, + "used": Set { + "watch", + }, + }, + "label": "path", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "comment": "这是注释11", + "line": 19, + }, + "label": "data", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 23, + }, + "label": "age", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 25, + }, + "label": "restArr", + "type": "var", + } => Set {}, + { + "info": { + "column": 11, + "line": 26, + }, + "label": "restObj", + "type": "var", + } => Set {}, + { + "info": { + "column": 9, + "line": 28, + }, + "label": "addAge", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "line": 23, + }, + "label": "age", + "type": "var", + }, + }, + { + "info": { + "column": 6, + "line": 32, + }, + "label": "updateName", + "type": "fun", + } => Set { + { + "info": { + "column": 6, + "comment": "这是注释11", + "line": 19, + }, + "label": "data", + "type": "var", + }, + }, + { + "info": { + "column": 9, + "line": 36, + }, + "label": "funA", + "type": "fun", + } => Set {}, + { + "info": { + "column": 8, + "line": 43, + }, + "label": "varB", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 36, + }, + "label": "funA", + "type": "fun", + }, + }, + { + "info": { + "column": 9, + "comment": "这是注释", + "line": 45, + "used": Set { + "onMounted", + "provide", + }, + }, + "label": "funC", + "type": "fun", + } => Set { + { + "info": { + "column": 9, + "comment": "这是注释", + "line": 45, + "used": Set { + "onMounted", + "provide", + }, + }, + "label": "funC", + "type": "fun", + }, + }, + { + "info": { + "column": 8, + "line": 52, + }, + "label": "varD", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "comment": "这是注释", + "line": 45, + "used": Set { + "onMounted", + "provide", + }, + }, + "label": "funC", + "type": "fun", + }, + { + "info": { + "column": 8, + "line": 43, + }, + "label": "varB", + "type": "var", + }, + }, + { + "info": { + "column": 14, + "line": 52, + }, + "label": "varE", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "comment": "这是注释", + "line": 45, + "used": Set { + "onMounted", + "provide", + }, + }, + "label": "funC", + "type": "fun", + }, + { + "info": { + "column": 8, + "line": 43, + }, + "label": "varB", + "type": "var", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 6, + "comment": "route", + "line": 7, + }, + "label": "route", + "type": "var", + }, + { + "info": { + "column": 6, + "comment": "path", + "line": 9, + "used": Set { + "watch", + }, + }, + "label": "path", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 11, + "used": Set { + "watch", + }, + }, + "label": "lmsg", + "type": "var", + }, + { + "info": { + "column": 6, + "comment": "这是注释11", + "line": 19, + }, + "label": "data", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 23, + }, + "label": "age", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 25, + }, + "label": "restArr", + "type": "var", + }, + { + "info": { + "column": 11, + "line": 26, + }, + "label": "restObj", + "type": "var", + }, + { + "info": { + "column": 9, + "line": 28, + }, + "label": "addAge", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 32, + }, + "label": "updateName", + "type": "fun", + }, + { + "info": { + "column": 9, + "line": 36, + }, + "label": "funA", + "type": "fun", + }, + { + "info": { + "column": 8, + "line": 43, + }, + "label": "varB", + "type": "var", + }, + { + "info": { + "column": 9, + "comment": "这是注释", + "line": 45, + "used": Set { + "onMounted", + "provide", + }, + }, + "label": "funC", + "type": "fun", + }, + { + "info": { + "column": 8, + "line": 52, + }, + "label": "varD", + "type": "var", + }, + { + "info": { + "column": 14, + "line": 52, + }, + "label": "varE", + "type": "var", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/setup-block.vue.nodes.txt b/test/output/vue/setup-block.vue.nodes.txt new file mode 100644 index 0000000..e1ba5db --- /dev/null +++ b/test/output/vue/setup-block.vue.nodes.txt @@ -0,0 +1,8 @@ +Set { + "lmsg", + "path", + "age", + "data", + "updateName", + "addAge", +} \ No newline at end of file diff --git a/test/output/vue/tsx1.vue.graph.txt b/test/output/vue/tsx1.vue.graph.txt new file mode 100644 index 0000000..75aef4c --- /dev/null +++ b/test/output/vue/tsx1.vue.graph.txt @@ -0,0 +1,764 @@ +{ + "edges": Map { + { + "info": { + "column": 10, + "line": 11, + }, + "label": "open", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 17, + }, + "label": "dds", + "type": "fun", + } => Set {}, + { + "info": { + "column": 10, + "line": 18, + }, + "label": "dds2", + "type": "fun", + } => Set {}, + { + "info": { + "column": 10, + "line": 19, + }, + "label": "dds3", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 18, + }, + "label": "dds2", + "type": "fun", + }, + }, + { + "info": { + "column": 10, + "line": 20, + }, + "label": "delayTime", + "type": "var", + } => Set {}, + { + "info": { + "column": 27, + "line": 20, + }, + "label": "d2", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 21, + }, + "label": "route", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 22, + }, + "label": "infoOpen", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + } => Set { + { + "info": { + "column": 12, + "line": 35, + }, + "label": "aa", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 22, + }, + "label": "infoOpen", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + }, + { + "info": { + "column": 4, + "line": 28, + }, + "label": "processInfo", + "type": "fun", + } => Set { + { + "info": { + "column": 12, + "line": 35, + }, + "label": "aa", + "type": "var", + }, + { + "info": { + "column": 4, + "line": 28, + }, + "label": "processInfo", + "type": "fun", + }, + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 22, + }, + "label": "infoOpen", + "type": "var", + }, + }, + { + "info": { + "column": 12, + "line": 34, + }, + "label": "a", + "type": "var", + } => Set { + { + "info": { + "column": 11, + "line": 38, + }, + "label": "arr", + "type": "var", + }, + }, + { + "info": { + "column": 15, + "line": 34, + }, + "label": "b", + "type": "var", + } => Set { + { + "info": { + "column": 11, + "line": 38, + }, + "label": "arr", + "type": "var", + }, + }, + { + "info": { + "column": 12, + "line": 35, + }, + "label": "aa", + "type": "var", + } => Set { + { + "info": { + "column": 16, + "line": 38, + }, + "label": "brr", + "type": "var", + }, + { + "info": { + "column": 63, + "line": 37, + }, + "label": "line", + "type": "var", + }, + }, + { + "info": { + "column": 16, + "line": 35, + }, + "label": "rest", + "type": "var", + } => Set { + { + "info": { + "column": 16, + "line": 38, + }, + "label": "brr", + "type": "var", + }, + { + "info": { + "column": 63, + "line": 37, + }, + "label": "line", + "type": "var", + }, + }, + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + } => Set {}, + { + "info": { + "column": 10, + "line": 37, + }, + "label": "loc", + "type": "var", + } => Set {}, + { + "info": { + "column": 15, + "line": 37, + }, + "label": "locd", + "type": "var", + } => Set {}, + { + "info": { + "column": 33, + "line": 37, + }, + "label": "start", + "type": "var", + } => Set {}, + { + "info": { + "column": 40, + "line": 37, + }, + "label": "end", + "type": "var", + } => Set {}, + { + "info": { + "column": 63, + "line": 37, + }, + "label": "line", + "type": "var", + } => Set {}, + { + "info": { + "column": 11, + "line": 38, + }, + "label": "arr", + "type": "var", + } => Set {}, + { + "info": { + "column": 16, + "line": 38, + }, + "label": "brr", + "type": "var", + } => Set {}, + { + "info": { + "column": 9, + "line": 39, + }, + "label": "foo", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + }, + { + "info": { + "column": 15, + "line": 39, + }, + "label": "bar", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + }, + { + "info": { + "column": 20, + "line": 39, + }, + "label": "baz", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + }, + { + "info": { + "column": 14, + "line": 40, + }, + "label": "third", + "type": "var", + } => Set {}, + { + "info": { + "column": 9, + "line": 41, + }, + "label": "xx", + "type": "var", + } => Set {}, + { + "info": { + "column": 13, + "line": 41, + }, + "label": "yy", + "type": "var", + } => Set {}, + { + "info": { + "column": 11, + "line": 42, + }, + "label": "arr2", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 39, + }, + "label": "foo", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 39, + }, + "label": "bar", + "type": "var", + }, + { + "info": { + "column": 20, + "line": 39, + }, + "label": "baz", + "type": "var", + }, + }, + { + "info": { + "column": 17, + "line": 42, + }, + "label": "rest2", + "type": "var", + } => Set { + { + "info": { + "column": 9, + "line": 39, + }, + "label": "foo", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 39, + }, + "label": "bar", + "type": "var", + }, + { + "info": { + "column": 20, + "line": 39, + }, + "label": "baz", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 43, + }, + "label": "c", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 37, + }, + "label": "loc", + "type": "var", + }, + { + "info": { + "column": 33, + "line": 37, + }, + "label": "start", + "type": "var", + }, + }, + { + "info": { + "column": 4, + "line": 44, + }, + "label": "xyz", + "type": "fun", + } => Set { + { + "info": { + "column": 4, + "line": 44, + }, + "label": "xyz", + "type": "fun", + }, + }, + }, + "nodes": Set { + { + "info": { + "column": 10, + "line": 11, + }, + "label": "open", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 17, + }, + "label": "dds", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 18, + }, + "label": "dds2", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 19, + }, + "label": "dds3", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 20, + }, + "label": "delayTime", + "type": "var", + }, + { + "info": { + "column": 27, + "line": 20, + }, + "label": "d2", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 21, + }, + "label": "route", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 22, + }, + "label": "infoOpen", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 23, + }, + "label": "writeBaseInfo", + "type": "fun", + }, + { + "info": { + "column": 4, + "line": 28, + }, + "label": "processInfo", + "type": "fun", + }, + { + "info": { + "column": 12, + "line": 34, + }, + "label": "a", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 34, + }, + "label": "b", + "type": "var", + }, + { + "info": { + "column": 12, + "line": 35, + }, + "label": "aa", + "type": "var", + }, + { + "info": { + "column": 16, + "line": 35, + }, + "label": "rest", + "type": "var", + }, + { + "info": { + "column": 9, + "line": 36, + }, + "label": "xq", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 37, + }, + "label": "loc", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 37, + }, + "label": "locd", + "type": "var", + }, + { + "info": { + "column": 33, + "line": 37, + }, + "label": "start", + "type": "var", + }, + { + "info": { + "column": 40, + "line": 37, + }, + "label": "end", + "type": "var", + }, + { + "info": { + "column": 63, + "line": 37, + }, + "label": "line", + "type": "var", + }, + { + "info": { + "column": 11, + "line": 38, + }, + "label": "arr", + "type": "var", + }, + { + "info": { + "column": 16, + "line": 38, + }, + "label": "brr", + "type": "var", + }, + { + "info": { + "column": 9, + "line": 39, + }, + "label": "foo", + "type": "var", + }, + { + "info": { + "column": 15, + "line": 39, + }, + "label": "bar", + "type": "var", + }, + { + "info": { + "column": 20, + "line": 39, + }, + "label": "baz", + "type": "var", + }, + { + "info": { + "column": 14, + "line": 40, + }, + "label": "third", + "type": "var", + }, + { + "info": { + "column": 9, + "line": 41, + }, + "label": "xx", + "type": "var", + }, + { + "info": { + "column": 13, + "line": 41, + }, + "label": "yy", + "type": "var", + }, + { + "info": { + "column": 11, + "line": 42, + }, + "label": "arr2", + "type": "var", + }, + { + "info": { + "column": 17, + "line": 42, + }, + "label": "rest2", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 43, + }, + "label": "c", + "type": "var", + }, + { + "info": { + "column": 4, + "line": 44, + }, + "label": "xyz", + "type": "fun", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/tsx1.vue.nodes.txt b/test/output/vue/tsx1.vue.nodes.txt new file mode 100644 index 0000000..542042c --- /dev/null +++ b/test/output/vue/tsx1.vue.nodes.txt @@ -0,0 +1,6 @@ +Set { + "open", + "writeBaseInfo", + "processInfo", + "xx", +} \ No newline at end of file diff --git a/test/output/vue/tsx2.vue.graph.txt b/test/output/vue/tsx2.vue.graph.txt new file mode 100644 index 0000000..374863c --- /dev/null +++ b/test/output/vue/tsx2.vue.graph.txt @@ -0,0 +1,128 @@ +{ + "edges": Map { + { + "info": { + "column": 10, + "line": 21, + }, + "label": "focus", + "type": "fun", + } => Set { + { + "info": { + "column": 10, + "line": 30, + }, + "label": "aa", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 27, + }, + "label": "x", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 30, + }, + "label": "aa", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 33, + }, + "label": "AA", + "type": "var", + } => Set { + { + "info": { + "column": 10, + "line": 30, + }, + "label": "aa", + "type": "var", + }, + }, + { + "info": { + "column": 10, + "line": 25, + }, + "label": "open", + "type": "fun", + } => Set {}, + { + "info": { + "column": 6, + "line": 27, + }, + "label": "x", + "type": "var", + } => Set {}, + { + "info": { + "column": 6, + "line": 28, + }, + "label": "y", + "type": "var", + } => Set {}, + }, + "nodes": Set { + { + "info": { + "column": 10, + "line": 21, + }, + "label": "focus", + "type": "fun", + }, + { + "info": { + "column": 10, + "line": 30, + }, + "label": "aa", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 33, + }, + "label": "AA", + "type": "var", + }, + { + "info": { + "column": 10, + "line": 25, + }, + "label": "open", + "type": "fun", + }, + { + "info": { + "column": 6, + "line": 27, + }, + "label": "x", + "type": "var", + }, + { + "info": { + "column": 6, + "line": 28, + }, + "label": "y", + "type": "var", + }, + }, +} \ No newline at end of file diff --git a/test/output/vue/tsx2.vue.nodes.txt b/test/output/vue/tsx2.vue.nodes.txt new file mode 100644 index 0000000..9dbc74f --- /dev/null +++ b/test/output/vue/tsx2.vue.nodes.txt @@ -0,0 +1,6 @@ +Set { + "a-modal", + "open", + "focus", + "aa", +} \ No newline at end of file diff --git a/test/setup-block/TestComponent.graph.ts b/test/setup-block/TestComponent.graph.ts deleted file mode 100644 index 898655f..0000000 --- a/test/setup-block/TestComponent.graph.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { TypedNode } from '@/analyze/utils'; -import { NodeType } from '@/analyze/utils'; - -const edges = new Map>(); - -const route: TypedNode = { label: 'route', type: NodeType.var, info: { line: 7, column: 6, comment: 'route' } }; -const path: TypedNode = { label: 'path', type: NodeType.var, info: { line: 9, column: 6, used: new Set(['watch']), comment: 'path' } }; -const lmsg: TypedNode = { label: 'lmsg', type: NodeType.var, info: { line: 11, column: 6, used: new Set(['watch']) } }; -const data: TypedNode = { label: 'data', type: NodeType.var, info: { line: 19, column: 6, comment: '这是注释11' } }; -const age: TypedNode = { label: 'age', type: NodeType.var, info: { line: 23, column: 6 } }; -const addAge: TypedNode = { label: 'addAge', type: NodeType.fun, info: { line: 28, column: 9 } }; -const updateName: TypedNode = { label: 'updateName', type: NodeType.fun, info: { line: 32, column: 6 } }; -const funA: TypedNode = { label: 'funA', type: NodeType.fun, info: { line: 36, column: 9 } }; -const varB: TypedNode = { label: 'varB', type: NodeType.var, info: { line: 43, column: 8 } }; -const funC: TypedNode = { label: 'funC', type: NodeType.fun, info: { line: 45, column: 9, comment: '这是注释', used: new Set(['onMounted', 'provide']) } }; -const varD: TypedNode = { label: 'varD', type: NodeType.var, info: { line: 52, column: 8 } }; -const varE: TypedNode = { label: 'varE', type: NodeType.var, info: { line: 52, column: 14 } }; -const restArr: TypedNode = { label: 'restArr', type: NodeType.var, info: { line: 25, column: 10 } }; -const restObj: TypedNode = { label: 'restObj', type: NodeType.var, info: { line: 26, column: 11 } }; - -edges.set(route, new Set([])); -edges.set(route, new Set([])); -edges.set(path, new Set([route])); -edges.set(lmsg, new Set([path])); -edges.set(data, new Set([])); -edges.set(age, new Set([])); -edges.set(restArr, new Set([])); -edges.set(restObj, new Set([])); -edges.set(addAge, new Set([age])); -edges.set(updateName, new Set([data])); -edges.set(funA, new Set([])); -edges.set(varB, new Set([funA])); -edges.set(funC, new Set([funC])); -edges.set(varD, new Set([funC, varB])); -edges.set(varE, new Set([funC, varB])); - -export const graph = { - nodes: new Set([route, path, lmsg, data, age, addAge, updateName, funA, varB, funC, varD, varE, restArr, restObj]), - edges, -}; diff --git a/test/setup-block/TestComponent.nodes.ts b/test/setup-block/TestComponent.nodes.ts deleted file mode 100644 index 8c080f4..0000000 --- a/test/setup-block/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['lmsg', 'path', 'data', 'age', 'updateName', 'addAge']); diff --git a/test/setup-block/index.test.ts b/test/setup-block/index.test.ts deleted file mode 100644 index 8e1cade..0000000 --- a/test/setup-block/index.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { analyzeSetupScript, analyzeTemplate, parse } from '@/index'; - -describe('test analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const sfc = parse(source); - it('test analyze setup script', () => { - const graph = analyzeSetupScript( - sfc.descriptor.scriptSetup?.content || '', - (sfc.descriptor.scriptSetup?.loc.start.line || 1) - 1, - ); - expect(graph).toEqual(graphRes); - }); - it('test analyze template', () => { - const nodes = analyzeTemplate(sfc.descriptor.template!.content); - expect(nodes).toEqual(nodesRes); - }); -}); diff --git a/test/tsx/TestComponent.graph.ts b/test/tsx/TestComponent.graph.ts deleted file mode 100644 index 2ea9370..0000000 --- a/test/tsx/TestComponent.graph.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { NodeType } from '@/analyze/utils'; - -const edges = new Map<{ - label: string - type: NodeType -}, Set<{ label: string, type: NodeType }>>(); - -const open = { label: 'open', type: NodeType.var }; -const dds = { label: 'dds', type: NodeType.fun }; -const dds2 = { label: 'dds2', type: NodeType.fun }; -const dds3 = { label: 'dds3', type: NodeType.var }; -const delayTime = { label: 'delayTime', type: NodeType.var }; -const d2 = { label: 'd2', type: NodeType.var }; -const route = { label: 'route', type: NodeType.var }; -const infoOpen = { label: 'infoOpen', type: NodeType.var }; -const writeBaseInfo = { label: 'writeBaseInfo', type: NodeType.fun }; -const processInfo = { label: 'processInfo', type: NodeType.fun }; -const a = { label: 'a', type: NodeType.var }; -const b = { label: 'b', type: NodeType.var }; -const aa = { label: 'aa', type: NodeType.var }; -const rest = { label: 'rest', type: NodeType.var }; -const xq = { label: 'xq', type: NodeType.var }; -const loc = { label: 'loc', type: NodeType.var }; -const locd = { label: 'locd', type: NodeType.var }; -const start = { label: 'start', type: NodeType.var }; -const end = { label: 'end', type: NodeType.var }; -const line = { label: 'line', type: NodeType.var }; -const arr = { label: 'arr', type: NodeType.var }; -const brr = { label: 'brr', type: NodeType.var }; -const foo = { label: 'foo', type: NodeType.var }; -const bar = { label: 'bar', type: NodeType.var }; -const baz = { label: 'baz', type: NodeType.var }; -const third = { label: 'third', type: NodeType.var }; -const xx = { label: 'xx', type: NodeType.var }; -const yy = { label: 'yy', type: NodeType.var }; -const arr2 = { label: 'arr2', type: NodeType.var }; -const rest2 = { label: 'rest2', type: NodeType.var }; -const c = { label: 'c', type: NodeType.var }; -const xyz = { label: 'xyz', type: NodeType.fun }; - -edges.set(open, new Set([])); -edges.set(dds, new Set([])); -edges.set(dds2, new Set([])); -edges.set(dds3, new Set([dds2])); -edges.set(delayTime, new Set([])); -edges.set(d2, new Set([])); -edges.set(route, new Set([])); -edges.set(infoOpen, new Set([])); -edges.set(writeBaseInfo, new Set([aa, infoOpen, writeBaseInfo])); -edges.set(processInfo, new Set([processInfo, aa, xq, infoOpen])); -edges.set(a, new Set([arr])); -edges.set(b, new Set([arr])); -edges.set(aa, new Set([brr, line])); -edges.set(rest, new Set([brr, line])); -edges.set(xq, new Set([])); -edges.set(loc, new Set([])); -edges.set(locd, new Set([])); -edges.set(start, new Set([])); -edges.set(end, new Set([])); -edges.set(line, new Set([])); -edges.set(arr, new Set([])); -edges.set(brr, new Set([])); -edges.set(foo, new Set([xq, writeBaseInfo])); -edges.set(bar, new Set([xq, writeBaseInfo])); -edges.set(baz, new Set([xq, writeBaseInfo])); -edges.set(third, new Set([])); -edges.set(xx, new Set([])); -edges.set(yy, new Set([])); -edges.set(arr2, new Set([foo, bar, baz])); -edges.set(rest2, new Set([foo, bar, baz])); -edges.set(c, new Set([loc, start])); -edges.set(xyz, new Set([xyz])); - -export const graph = { - nodes: new Set([ - open, - dds, - dds2, - dds3, - delayTime, - d2, - route, - infoOpen, - writeBaseInfo, - processInfo, - a, - b, - aa, - rest, - xq, - loc, - locd, - start, - end, - line, - arr, - brr, - foo, - bar, - baz, - third, - xx, - yy, - arr2, - rest2, - c, - xyz, - ]), - edges, -}; diff --git a/test/tsx/TestComponent.graph2.ts b/test/tsx/TestComponent.graph2.ts deleted file mode 100644 index 03573e0..0000000 --- a/test/tsx/TestComponent.graph2.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { NodeType } from '@/analyze/utils'; - -const edges = new Map<{ - label: string - type: NodeType -}, Set<{ label: string, type: NodeType }>>(); - -const focus = { label: 'focus', type: NodeType.fun }; -const open = { label: 'open', type: NodeType.fun }; -const AA = { label: 'AA', type: NodeType.var }; -const aa = { label: 'aa', type: NodeType.var }; -const x = { label: 'x', type: NodeType.var }; -const y = { label: 'y', type: NodeType.var }; - -edges.set(focus, new Set([aa, x])); -edges.set(aa, new Set([])); -edges.set(AA, new Set([aa])); -edges.set(x, new Set([])); -edges.set(y, new Set([])); -edges.set(open, new Set([])); - -export const graph = { - nodes: new Set([ - focus, - aa, - AA, - x, - y, - open, - ]), - edges, -}; diff --git a/test/tsx/TestComponent.graph3.ts b/test/tsx/TestComponent.graph3.ts deleted file mode 100644 index c3582d0..0000000 --- a/test/tsx/TestComponent.graph3.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { NodeType } from '@/analyze/utils'; - -const edges = new Map<{ - label: string - type: NodeType -}, Set<{ label: string, type: NodeType }>>(); - -const store = { label: 'store', type: NodeType.var }; -const configLoaded = { label: 'configLoaded', type: NodeType.var }; -const config = { label: 'config', type: NodeType.var }; -const terminalFullScreen = { label: 'terminalFullScreen', type: NodeType.var }; -const pinned = { label: 'pinned', type: NodeType.var }; -const isSencondInstance = { label: 'isSencondInstance', type: NodeType.var }; -const pinnedQuickCommandBar = { label: 'pinnedQuickCommandBar', type: NodeType.var }; -const wsInited = { label: 'wsInited', type: NodeType.var }; -const upgradeInfo = { label: 'upgradeInfo', type: NodeType.var }; -const installSrc = { label: 'installSrc', type: NodeType.var }; -const uiThemeConfig = { label: 'uiThemeConfig', type: NodeType.var }; -const cls = { label: 'cls', type: NodeType.var }; -const ext1 = { label: 'ext1', type: NodeType.var }; -const cpConf = { label: 'cpConf', type: NodeType.var }; -const confsCss = { label: 'confsCss', type: NodeType.var }; -const themeProps = { label: 'themeProps', type: NodeType.var }; -const outerProps = { label: 'outerProps', type: NodeType.var }; - -edges.set(store, new Set([])); -edges.set(configLoaded, new Set([])); -edges.set(config, new Set([])); -edges.set(terminalFullScreen, new Set([])); -edges.set(pinned, new Set([])); -edges.set(isSencondInstance, new Set([])); -edges.set(pinnedQuickCommandBar, new Set([])); -edges.set(wsInited, new Set([])); -edges.set(upgradeInfo, new Set([])); -edges.set(installSrc, new Set([])); -edges.set(uiThemeConfig, new Set([])); -edges.set(cls, new Set([configLoaded, store, pinned, pinnedQuickCommandBar, terminalFullScreen, isSencondInstance])); -edges.set(ext1, new Set([cls])); -edges.set(cpConf, new Set([])); -edges.set(confsCss, new Set([cpConf])); -edges.set(themeProps, new Set([store])); -edges.set(outerProps, new Set([config])); - -export const graph = { - nodes: new Set([ - store, - configLoaded, - config, - terminalFullScreen, - pinned, - isSencondInstance, - pinnedQuickCommandBar, - wsInited, - upgradeInfo, - installSrc, - uiThemeConfig, - cls, - ext1, - cpConf, - confsCss, - themeProps, - outerProps, - ]), - edges, -}; diff --git a/test/tsx/TestComponent.graph4.ts b/test/tsx/TestComponent.graph4.ts deleted file mode 100644 index ee26850..0000000 --- a/test/tsx/TestComponent.graph4.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { NodeType } from '@/analyze/utils'; - -const edges = new Map<{ - label: string - type: NodeType -}, Set<{ label: string, type: NodeType }>>(); - -const open = { label: 'open', type: NodeType.var }; -const setOpen = { label: 'setOpen', type: NodeType.var }; -const xx = { label: 'xx', type: NodeType.var }; -const processInfo = { label: 'processInfo', type: NodeType.fun }; -const writeBaseInfo = { label: 'writeBaseInfo', type: NodeType.fun }; - -edges.set(open, new Set([])); -edges.set(setOpen, new Set([])); -edges.set(xx, new Set([])); -edges.set(processInfo, new Set([open])); -edges.set(writeBaseInfo, new Set([xx])); - -export const graph = { - nodes: new Set([ - open, - setOpen, - xx, - processInfo, - writeBaseInfo, - ]), - edges, -}; diff --git a/test/tsx/TestComponent.nodes.ts b/test/tsx/TestComponent.nodes.ts deleted file mode 100644 index 9b707a4..0000000 --- a/test/tsx/TestComponent.nodes.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['open', 'writeBaseInfo', 'processInfo', 'xx']); diff --git a/test/tsx/TestComponent.nodes2.ts b/test/tsx/TestComponent.nodes2.ts deleted file mode 100644 index b30be8c..0000000 --- a/test/tsx/TestComponent.nodes2.ts +++ /dev/null @@ -1 +0,0 @@ -export const nodes = new Set(['open', 'aa']); diff --git a/test/tsx/TestComponent.nodes3.ts b/test/tsx/TestComponent.nodes3.ts deleted file mode 100644 index 3ab3701..0000000 --- a/test/tsx/TestComponent.nodes3.ts +++ /dev/null @@ -1,14 +0,0 @@ -export const nodes = new Set([ - 'uiThemeConfig', - 'ext1', - 'wsInited', - 'terminalFullScreen', - 'confsCss', - 'wsInited', - 'themeProps', - 'store', - 'cpConf', - 'upgradeInfo', - 'installSrc', - 'outerProps', -]); diff --git a/test/tsx/TestComponent.nodes4.ts b/test/tsx/TestComponent.nodes4.ts deleted file mode 100644 index 6ae6a3a..0000000 --- a/test/tsx/TestComponent.nodes4.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const nodes = new Set([ - 'open', - 'writeBaseInfo', - 'processInfo', - 'setOpen', - 'xx', -]); diff --git a/test/tsx/index.test.ts b/test/tsx/index.test.ts deleted file mode 100644 index 74d5df6..0000000 --- a/test/tsx/index.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import * as fs from 'node:fs'; -import path from 'node:path'; - -import { graph as graphRes } from './TestComponent.graph'; -import { graph as graphRes2 } from './TestComponent.graph2'; -import { graph as graphRes3 } from './TestComponent.graph3'; -import { graph as graphRes4 } from './TestComponent.graph4'; -import { nodes as nodesRes } from './TestComponent.nodes'; -import { nodes as nodesRes2 } from './TestComponent.nodes2'; -import { nodes as nodesRes3 } from './TestComponent.nodes3'; -import { nodes as nodesRes4 } from './TestComponent.nodes4'; -import { analyzeTemplate, analyzeTsx, parse } from '@/index'; - -describe('test vue analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent.vue'), 'utf-8'); - const source2 = fs.readFileSync(path.resolve(__dirname, './TestComponent2.vue'), 'utf-8'); - const sfc = parse(source); - const sfc2 = parse(source2); - - it('test analyze tsx setup', () => { - const { graph, nodesUsedInTemplate } = analyzeTsx( - sfc.descriptor.script?.content || '', - 'vue', - (sfc.descriptor.script?.loc.start.line || 1) - 1, - false, - ); - - expect(graph).toEqual(graphRes); - expect(nodesUsedInTemplate).toEqual(nodesRes); - }); - - it('test analyze tsx setup not jsx', () => { - const { graph } = analyzeTsx( - sfc2.descriptor.script?.content || '', - 'vue', - (sfc2.descriptor.script?.loc.start.line || 1) - 1, - false, - ); - - expect(graph).toEqual(graphRes2); - }); -}); - -describe('test react analyze', () => { - const source = fs.readFileSync(path.resolve(__dirname, './TestComponent3.jsx'), 'utf-8'); - const source2 = fs.readFileSync(path.resolve(__dirname, './TestComponent4.jsx'), 'utf-8'); - - it('test analyze react jsx class', () => { - const { graph, nodesUsedInTemplate } = analyzeTsx( - source, - 'react', - 0, - false, - ); - expect(graph).toEqual(graphRes3); - expect(nodesUsedInTemplate).toEqual(nodesRes3); - }); - it('test analyze react jsx function', () => { - const { graph, nodesUsedInTemplate } = analyzeTsx( - source2, - 'react', - 0, - false, - ); - expect(graph).toEqual(graphRes4); - expect(nodesUsedInTemplate).toEqual(nodesRes4); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index 83fdd4a..97b194b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,5 +27,5 @@ "skipLibCheck": true }, "include": ["src", "test", "vitest.config.ts", "tsup.config.ts", "unocss.config.ts"], - "exclude": ["node_modules", "dist", "packages"] + "exclude": ["node_modules", "dist", "packages", "fixtures", "test/output"] }