From bdaf65802ebf78682f23c79e68a01a280d684ab5 Mon Sep 17 00:00:00 2001 From: y1j2x34 Date: Tue, 24 Sep 2024 21:27:53 +0800 Subject: [PATCH] chore: delete @vgerbot/tschannel-transformer --- .github/workflows/runtest.yml | 6 +- package.json | 2 - packages/examples/package.json | 1 - packages/examples/tsconfig.json | 5 +- packages/transformer/.eslintignore | 6 - packages/transformer/.eslintrc | 28 -- packages/transformer/.prettierrc | 10 - packages/transformer/README.md | 144 ----------- packages/transformer/jest.config.js | 14 - .../lib/ChannelProgramContext.d.ts | 22 -- .../transformer/lib/ChannelProgramContext.js | 165 ------------ .../lib/ChannelProgramContext.js.map | 1 - .../transformer/lib/TransformerOptions.d.ts | 3 - .../transformer/lib/TransformerOptions.js | 3 - .../transformer/lib/TransformerOptions.js.map | 1 - packages/transformer/lib/consts.d.ts | 2 - packages/transformer/lib/consts.js | 6 - packages/transformer/lib/consts.js.map | 1 - packages/transformer/lib/index.d.ts | 5 - packages/transformer/lib/index.js | 208 --------------- packages/transformer/lib/index.js.map | 1 - packages/transformer/lib/utils.d.ts | 5 - packages/transformer/lib/utils.js | 43 ---- packages/transformer/lib/utils.js.map | 1 - packages/transformer/package.json | 74 ------ .../transformer/src/ChannelProgramContext.ts | 170 ------------- .../transformer/src/TransformerOptions.ts | 4 - packages/transformer/src/consts.ts | 4 - packages/transformer/src/index.ts | 239 ------------------ packages/transformer/src/utils.ts | 40 --- packages/transformer/test/common/compiler.ts | 104 -------- .../transformer/test/common/load-fixture.ts | 54 ---- .../test/fixtures/abstract class.ts | 7 - .../test/fixtures/autofill parameters.ts | 6 - .../test/fixtures/automatic method id.ts | 13 - .../test/fixtures/channel builder.ts | 10 - .../transformer/test/fixtures/def class.ts | 18 -- .../test/fixtures/interface parameter.ts | 6 - .../test/fixtures/intersection type.ts | 11 - .../test/fixtures/special/alias.ts | 6 - .../class id strategy first-interface.ts | 20 -- .../special/class id strategy first-parent.ts | 20 -- .../detect anonymous arrow functions.ts | 6 - .../special/detect anonymous functions.ts | 6 - .../fixtures/special/exclude 2 arguments.ts | 11 - .../special/exclude without type arguments.ts | 7 - .../test/fixtures/special/normal.ts | 3 - .../test/fixtures/special/reference class.ts | 6 - .../special/reuse converted variables.ts | 22 -- .../test/fixtures/type statement.ts | 6 - .../transformer/test/fixtures/union type.ts | 14 - .../specs/__snapshots__/index.spec.ts.snap | 221 ---------------- packages/transformer/test/specs/index.spec.ts | 123 --------- packages/transformer/test/tsconfig.json | 11 - packages/transformer/tsconfig.json | 19 -- scripts/build.mjs | 9 +- scripts/run.mjs | 5 +- scripts/workspace-name.mjs | 10 +- 58 files changed, 12 insertions(+), 1956 deletions(-) delete mode 100644 packages/transformer/.eslintignore delete mode 100644 packages/transformer/.eslintrc delete mode 100644 packages/transformer/.prettierrc delete mode 100644 packages/transformer/README.md delete mode 100644 packages/transformer/jest.config.js delete mode 100644 packages/transformer/lib/ChannelProgramContext.d.ts delete mode 100644 packages/transformer/lib/ChannelProgramContext.js delete mode 100644 packages/transformer/lib/ChannelProgramContext.js.map delete mode 100644 packages/transformer/lib/TransformerOptions.d.ts delete mode 100644 packages/transformer/lib/TransformerOptions.js delete mode 100644 packages/transformer/lib/TransformerOptions.js.map delete mode 100644 packages/transformer/lib/consts.d.ts delete mode 100644 packages/transformer/lib/consts.js delete mode 100644 packages/transformer/lib/consts.js.map delete mode 100644 packages/transformer/lib/index.d.ts delete mode 100644 packages/transformer/lib/index.js delete mode 100644 packages/transformer/lib/index.js.map delete mode 100644 packages/transformer/lib/utils.d.ts delete mode 100644 packages/transformer/lib/utils.js delete mode 100644 packages/transformer/lib/utils.js.map delete mode 100644 packages/transformer/package.json delete mode 100644 packages/transformer/src/ChannelProgramContext.ts delete mode 100644 packages/transformer/src/TransformerOptions.ts delete mode 100644 packages/transformer/src/consts.ts delete mode 100644 packages/transformer/src/index.ts delete mode 100644 packages/transformer/src/utils.ts delete mode 100644 packages/transformer/test/common/compiler.ts delete mode 100644 packages/transformer/test/common/load-fixture.ts delete mode 100644 packages/transformer/test/fixtures/abstract class.ts delete mode 100644 packages/transformer/test/fixtures/autofill parameters.ts delete mode 100644 packages/transformer/test/fixtures/automatic method id.ts delete mode 100644 packages/transformer/test/fixtures/channel builder.ts delete mode 100644 packages/transformer/test/fixtures/def class.ts delete mode 100644 packages/transformer/test/fixtures/interface parameter.ts delete mode 100644 packages/transformer/test/fixtures/intersection type.ts delete mode 100644 packages/transformer/test/fixtures/special/alias.ts delete mode 100644 packages/transformer/test/fixtures/special/class id strategy first-interface.ts delete mode 100644 packages/transformer/test/fixtures/special/class id strategy first-parent.ts delete mode 100644 packages/transformer/test/fixtures/special/detect anonymous arrow functions.ts delete mode 100644 packages/transformer/test/fixtures/special/detect anonymous functions.ts delete mode 100644 packages/transformer/test/fixtures/special/exclude 2 arguments.ts delete mode 100644 packages/transformer/test/fixtures/special/exclude without type arguments.ts delete mode 100644 packages/transformer/test/fixtures/special/normal.ts delete mode 100644 packages/transformer/test/fixtures/special/reference class.ts delete mode 100644 packages/transformer/test/fixtures/special/reuse converted variables.ts delete mode 100644 packages/transformer/test/fixtures/type statement.ts delete mode 100644 packages/transformer/test/fixtures/union type.ts delete mode 100644 packages/transformer/test/specs/__snapshots__/index.spec.ts.snap delete mode 100644 packages/transformer/test/specs/index.spec.ts delete mode 100644 packages/transformer/test/tsconfig.json delete mode 100644 packages/transformer/tsconfig.json diff --git a/.github/workflows/runtest.yml b/.github/workflows/runtest.yml index 0732a93..4e896be 100644 --- a/.github/workflows/runtest.yml +++ b/.github/workflows/runtest.yml @@ -43,14 +43,10 @@ jobs: run: yarn workspace @vgerbot/channel test - name: Build @vgerbot/channel run: yarn workspace @vgerbot/channel build - - name: Test @vgerbot/channel-transformer - run: yarn workspace @vgerbot/channel-transformer test - name: Upload coverage data of @vgerbot/channel to codecov run: yarn workspace @vgerbot/channel codecov - - name: Upload coverage data pf @vgerbot/channel-transformer to codecov - run: yarn workspace @vgerbot/channel-transformer codecov - name: Upload coverage reports to codacy uses: codacy/codacy-coverage-reporter-action@master with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} - coverage-reports: packages/core/coverage/cobertura-coverage.xml,packages/transformer/coverage/cobertura-coverage.xml + coverage-reports: packages/core/coverage/cobertura-coverage.xml diff --git a/package.json b/package.json index 2c5b2ee..b723f2f 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,6 @@ "scripts": { "commit": "git-cz", "lint:all": "zx ./scripts/run.mjs lint", - "transformer": "yarn workspace @vgerbot/channel-transformer", - "transformer:test": "yarn workspace @vgerbot/channel-transformer test", "debug:ci": "yarn workspace @vgerbot/channel debug:ci", "example": "yarn workspace @vgerbot/channel-examples start", "build": "zx ./scripts/build.mjs", diff --git a/packages/examples/package.json b/packages/examples/package.json index 8f7ea99..be8f09f 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -12,7 +12,6 @@ "private": true, "devDependencies": { "@parcel/ts-utils": "^2.7.0", - "@vgerbot/channel-transformer": "1.0.0", "@vgerbot/parcel-transformer-ttypescript": "^1.0.2", "eslint-config-prettier": "^8.5.0", "parcel": "^2.7.0", diff --git a/packages/examples/tsconfig.json b/packages/examples/tsconfig.json index 69683f0..22e126b 100644 --- a/packages/examples/tsconfig.json +++ b/packages/examples/tsconfig.json @@ -23,10 +23,7 @@ "listFiles": true, "forceConsistentCasingInFileNames": true, "experimentalDecorators": true, - "esModuleInterop": true, - "plugins": [{ - "transform": "@vgerbot/channel-transformer" - }] + "esModuleInterop": true }, "include": [ "./**/src" diff --git a/packages/transformer/.eslintignore b/packages/transformer/.eslintignore deleted file mode 100644 index 5da20a3..0000000 --- a/packages/transformer/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -commitlint.config.js -jest.config.js -{dist,test_dist}/**/*.js -test/fixtures -test/mock -node_modules diff --git a/packages/transformer/.eslintrc b/packages/transformer/.eslintrc deleted file mode 100644 index 8703b7f..0000000 --- a/packages/transformer/.eslintrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module", - "ecmaFeatures": { - "impliedStrict": true - }, - "project": ["./tsconfig.json", "./test/tsconfig.json"] - }, - "extends": [ - "plugin:@typescript-eslint/recommended", // Use the recommended rules from the @typescript-eslint/eslint-plugin - "prettier", - "plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier - ], - "rules": { - "prettier/prettier": "error", - "no-var-require": "off", - "no-console": "off", - "no-bitwise": "off", - "sort-imports": "warn", - "quotes": ["error", "single"], - "max-len": ["error", 120], - "@typescript-eslint/no-inferrable-types": "off", - "@typescript-eslint/ban-types": "off", - "comma-dangle": "off" - } -} diff --git a/packages/transformer/.prettierrc b/packages/transformer/.prettierrc deleted file mode 100644 index a607e8e..0000000 --- a/packages/transformer/.prettierrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "singleQuote": true, - "parser": "typescript", - "tabWidth": 4, - "bracketSpacing": true, - "printWidth": 120, - "endOfLine": "lf", - "arrowParens": "avoid", - "trailingComma": "none" -} diff --git a/packages/transformer/README.md b/packages/transformer/README.md deleted file mode 100644 index d9c8040..0000000 --- a/packages/transformer/README.md +++ /dev/null @@ -1,144 +0,0 @@ -# @vgerbot/channel-transformer - -A typescript transformer, which is used to simplify the use of the [@vgerbot/channel](https://npmjs.com/package/@vgerbot/channel) library. -It has the following conversion features: - -- Convert the members of the interface passed to the `get_class` method to an array: - - ```ts - // Automatically the generate class id - interface RmAPI { - method(); - } - - // before: - chnl.get_class(); - // after transformed: - var RmAPIMembers1 = ['method']; - chnl.get_class('RmAPI', RmAPIMembers1); - ``` - ```ts - // Use Interface name as class Id - interface RmAPI { - method(); - } - - // before - chnl.get_class('other-RmAPI'); - // after - var RmAPIMembers1 = ['method']; - chnl.get_class('other-RmAPI', RmAPIMembers1); - ``` - -- Auto-generated class id and passed to `def_class` method: - - ```ts - class ClassA {} - // before - chnl.def_class(ClassA); - // after - chnl.def_class('ClassA', ClassA); - ``` - ```ts - interface API { - method(); - } - class APIImpl implements API{ - method() {} - } - // before - chnl.def_class(APIImpl); - // after - chnl.def_class('APIImpl', APIImpl); - ``` - -- Auto-generated method id and passed to `def_method` method: - - ```ts - // before - chnl.def_method(function named_method() {}); - // after - chnl.def_method('named_method', function named_method() {}); - ``` - ```ts - function named_method() {} - // before - chnl.def_method(named_method); - // after - chnl.def_method('named_method', named_method); - ``` - ```ts - const named_method = () => {}; - // before - chnl.def_method(named_method); - // after - chnl.def_method('named_method', named_method); - ``` - -For more examples, please refer to Unit Tests and Snapshots. - -## Requirement - -Typescript >= 3.2.2 - -## Setup - -### Webpack(with ts-loader or awesome-typescript-loader) - -```js -// webpack.config.js -const tschannelTransformer = require('@vgerbot/channel-transformer').default; -module.exports = { - // ... - module: { - rules: [{ - test: /\.tsx?/, - loader: 'ts-loader', // or 'awesome-typescript-loader' - options: { - getCustomTransformers:program => tschannelTransformer(program) - } - }] - } -} -``` - -### Rollup(with rollup-plugin-typescript2) - -```js -// rollup.config.js -import typescript from "rollup-plugin-typescript2"; -const tschannelTransformer = require('@vgerbot/channel-transformer').default; -export default { - // ... - plugins: [ - typescript({ - transformers: [ - (languageService) => { - const program = languageService.getProgram(); - return { - before: [tschannelTransformer(program)] - }; - } - ] - }) - ] -}; -``` - -### ttypescript - -tsconfig.json - -```json -{ - "compilerOptions": { - "plugins": [{ - "transform": "@vgerbot/channel-transformer" - }] - } -} -``` - -## License - -[![License MIT](https://badgen.net/github/license/y1j2x34/tschannel)](https://github.com/y1j2x34/tschannel/blob/master/LICENSE) diff --git a/packages/transformer/jest.config.js b/packages/transformer/jest.config.js deleted file mode 100644 index f385333..0000000 --- a/packages/transformer/jest.config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - coverageDirectory: './coverage', - coverageReporters: [ - "text", - "cobertura", - "lcov" - ], - collectCoverageFrom: [ - "src/**/*.ts" - ], - testRegex: /test\/specs\/.+\.spec\.[jt]s$/.source -}; diff --git a/packages/transformer/lib/ChannelProgramContext.d.ts b/packages/transformer/lib/ChannelProgramContext.d.ts deleted file mode 100644 index abed2a8..0000000 --- a/packages/transformer/lib/ChannelProgramContext.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import ts from 'typescript'; -export interface ChannelSymbols { - channelMethodSymbol: ts.Symbol; - channelClassSymbol: ts.Symbol; -} -export declare class ChannelProgramContext { - private readonly typeChecker; - constructor(typeChecker: ts.TypeChecker, channelSymbols: ChannelSymbols); - channelMethodSymbols: Set; - channelClassSymbols: Set; - variablesMap: Map; - channel_variables: Set; - isAccessingDefClassMethod(callExpression: ts.CallExpression, propertyExpression: ts.PropertyAccessExpression): boolean; - isAccessingDefMethodMethod(callExpression: ts.CallExpression, propertyExpression: ts.PropertyAccessExpression): boolean; - isAccessingTheGetClassMethod(callExpression: ts.CallExpression, propertyExpression: ts.PropertyAccessExpression): boolean; - recordChannelVariableByBinaryExpression(node: ts.BinaryExpression): void; - recordChannelVariableIfPossible(node: ts.VariableDeclaration): void; - private isChannelInstanceInitializerExpression; - isChannelMethodSymbol(symbol: undefined | ts.Symbol): symbol is ts.Symbol; - isChannelClassSymbol(symbol: undefined | ts.Symbol): symbol is ts.Symbol; - recordChannelSymbolIfPossible(node: ts.ImportDeclaration): void; -} diff --git a/packages/transformer/lib/ChannelProgramContext.js b/packages/transformer/lib/ChannelProgramContext.js deleted file mode 100644 index 36180b8..0000000 --- a/packages/transformer/lib/ChannelProgramContext.js +++ /dev/null @@ -1,165 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ChannelProgramContext = void 0; -const tslib_1 = require("tslib"); -const typescript_1 = tslib_1.__importDefault(require("typescript")); -const utils_1 = require("./utils"); -class ChannelProgramContext { - constructor(typeChecker, channelSymbols) { - this.typeChecker = typeChecker; - this.channelMethodSymbols = new Set(); - this.channelClassSymbols = new Set(); - this.variablesMap = new Map(); - this.channel_variables = new Set(); - this.channelClassSymbols.add(channelSymbols.channelClassSymbol); - this.channelMethodSymbols.add(channelSymbols.channelMethodSymbol); - } - isAccessingDefClassMethod(callExpression, propertyExpression) { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'def_class') { - return false; - } - const args = callExpression.arguments; - if (args.length !== 1) { - return false; - } - const argSymbol = this.typeChecker.getSymbolAtLocation(args[0]); - const declaration = argSymbol === null || argSymbol === void 0 ? void 0 : argSymbol.valueDeclaration; - return !!declaration && typescript_1.default.isClassDeclaration(declaration); - } - isAccessingDefMethodMethod(callExpression, propertyExpression) { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'def_method') { - return false; - } - const args = callExpression.arguments; - if (args.length !== 1) { - return false; - } - const expressionType = this.typeChecker.getTypeAtLocation(propertyExpression.expression); - if (expressionType && !this.isChannelClassSymbol(expressionType.getSymbol())) { - return false; - } - if (typescript_1.default.isArrowFunction(args[0])) { - throw new Error('The first function parameter of Channel.def_method cannot be anonymous'); - } - if (typescript_1.default.isFunctionExpression(args[0])) { - const functionName = args[0].name; - if (!functionName) { - throw new Error('The first function parameter of Channel.def_method cannot be anonymous'); - } - return true; - } - else if (typescript_1.default.isIdentifier(args[0])) { - const symbol = this.typeChecker.getSymbolAtLocation(args[0]); - if (symbol) { - const declaration = symbol.declarations ? symbol.declarations[0] : undefined; - if (declaration && typescript_1.default.isFunctionDeclaration(declaration)) { - return true; - } - } - } - return false; - } - isAccessingTheGetClassMethod(callExpression, propertyExpression) { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'get_class') { - return false; - } - const typeArgs = (0, utils_1.getTypeArguments)(callExpression); - if (!typeArgs || typeArgs.length < 1) { - return false; - } - const expressionType = this.typeChecker.getTypeAtLocation(propertyExpression.expression); - if (expressionType && this.isChannelClassSymbol(expressionType.getSymbol())) { - return true; - } - const LeftHandSideExpressionSymbol = this.typeChecker.getSymbolAtLocation(propertyExpression.expression); - return !!LeftHandSideExpressionSymbol && this.channel_variables.has(LeftHandSideExpressionSymbol); - } - recordChannelVariableByBinaryExpression(node) { - const typeChecker = this.typeChecker; - const variables = this.channel_variables; - const variableSymbol = typeChecker.getSymbolAtLocation(node.left); - if (!variableSymbol) { - return; - } - if (this.isChannelInstanceInitializerExpression(node.right)) { - variables.add(variableSymbol); - } - } - recordChannelVariableIfPossible(node) { - const typeChecker = this.typeChecker; - const variables = this.channel_variables; - const initializer = node.initializer; - if (!initializer) { - return; - } - const variableSymbol = typeChecker.getSymbolAtLocation(node.name); - if (!variableSymbol) { - return; - } - if (this.isChannelInstanceInitializerExpression(initializer)) { - variables.add(variableSymbol); - } - } - isChannelInstanceInitializerExpression(initializer) { - const typeChecker = this.typeChecker; - if (typescript_1.default.isNewExpression(initializer)) { - const classSymbol = typeChecker.getSymbolAtLocation(initializer.expression); - if (this.isChannelClassSymbol(classSymbol)) { - return true; - } - } - else if (typescript_1.default.isCallExpression(initializer)) { - let expression = initializer.expression; - while (true) { - if (typescript_1.default.isCallExpression(expression)) { - expression = expression.expression; - } - else if (typescript_1.default.isPropertyAccessExpression(expression)) { - expression = expression.expression; - } - else { - break; - } - } - if (typescript_1.default.isIdentifier(expression)) { - const symbol = typeChecker.getSymbolAtLocation(expression); - if (this.isChannelMethodSymbol(symbol)) { - return true; - } - if (symbol) { - return this.channel_variables.has(symbol); - } - } - } - return false; - } - isChannelMethodSymbol(symbol) { - return !!symbol && this.channelMethodSymbols.has(symbol); - } - isChannelClassSymbol(symbol) { - return !!symbol && this.channelClassSymbols.has(symbol); - } - recordChannelSymbolIfPossible(node) { - var _a; - const namedBindings = (_a = node.importClause) === null || _a === void 0 ? void 0 : _a.namedBindings; - if (namedBindings && typescript_1.default.isNamedImports(namedBindings)) { - const importElementsArray = namedBindings.elements.map(it => { - const name = it.propertyName ? it.propertyName.text : it.name.text; - return { name, importSpecifier: it, symbol: this.typeChecker.getSymbolAtLocation(it.name) }; - }); - const { symbol: channelMethodSymbol } = importElementsArray.find(it => it.name === 'channel') || {}; - if (channelMethodSymbol) { - this.channelMethodSymbols.add(channelMethodSymbol); - } - const { symbol: channelClassSymbol } = importElementsArray.find(it => it.name === 'Channel') || {}; - if (channelClassSymbol) { - this.channelClassSymbols.add(channelClassSymbol); - } - } - } -} -exports.ChannelProgramContext = ChannelProgramContext; -//# sourceMappingURL=ChannelProgramContext.js.map \ No newline at end of file diff --git a/packages/transformer/lib/ChannelProgramContext.js.map b/packages/transformer/lib/ChannelProgramContext.js.map deleted file mode 100644 index 42c7a93..0000000 --- a/packages/transformer/lib/ChannelProgramContext.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ChannelProgramContext.js","sourceRoot":"","sources":["../src/ChannelProgramContext.ts"],"names":[],"mappings":";;;;AAAA,oEAA4B;AAC5B,mCAA2C;AAO3C,MAAa,qBAAqB;IAC9B,YAA6B,WAA2B,EAAE,cAA8B;QAA3D,gBAAW,GAAX,WAAW,CAAgB;QAKjD,yBAAoB,GAAG,IAAI,GAAG,EAAa,CAAC;QAC5C,wBAAmB,GAAG,IAAI,GAAG,EAAa,CAAC;QAC3C,iBAAY,GAAG,IAAI,GAAG,EAAmC,CAAC;QAC1D,sBAAiB,GAAG,IAAI,GAAG,EAAa,CAAC;QAP5C,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;QAChE,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,cAAc,CAAC,mBAAmB,CAAC,CAAC;IACtE,CAAC;IAOD,yBAAyB,CACrB,cAAiC,EACjC,kBAA+C;QAE/C,MAAM,YAAY,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;QAClD,IAAI,YAAY,KAAK,WAAW,EAAE;YAC9B,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,IAAI,GAAG,cAAc,CAAC,SAAS,CAAC;QACtC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACnB,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,IAAI,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AAE,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAChG,CAAC,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YACpG,IAAI,mBAAmB,EAAE;gBACrB,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;aACtD;YACD,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YACnG,IAAI,kBAAkB,EAAE;gBACpB,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;aACpD;SACJ;IACL,CAAC;CACJ;AAjKD,sDAiKC"} \ No newline at end of file diff --git a/packages/transformer/lib/TransformerOptions.d.ts b/packages/transformer/lib/TransformerOptions.d.ts deleted file mode 100644 index fd64717..0000000 --- a/packages/transformer/lib/TransformerOptions.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface TransformerOptions { - classIdStrategy: 'self' | 'first-interface' | 'first-parent'; -} diff --git a/packages/transformer/lib/TransformerOptions.js b/packages/transformer/lib/TransformerOptions.js deleted file mode 100644 index 8103c9c..0000000 --- a/packages/transformer/lib/TransformerOptions.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=TransformerOptions.js.map \ No newline at end of file diff --git a/packages/transformer/lib/TransformerOptions.js.map b/packages/transformer/lib/TransformerOptions.js.map deleted file mode 100644 index 26b21ab..0000000 --- a/packages/transformer/lib/TransformerOptions.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"TransformerOptions.js","sourceRoot":"","sources":["../src/TransformerOptions.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/packages/transformer/lib/consts.d.ts b/packages/transformer/lib/consts.d.ts deleted file mode 100644 index ab627fa..0000000 --- a/packages/transformer/lib/consts.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export declare const CHANNEL_MODULE_NAME = "@vgerbot/channel"; -export declare const DEFAULT_TRANSFORMER_OPTIONS: {}; diff --git a/packages/transformer/lib/consts.js b/packages/transformer/lib/consts.js deleted file mode 100644 index 5d6b190..0000000 --- a/packages/transformer/lib/consts.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DEFAULT_TRANSFORMER_OPTIONS = exports.CHANNEL_MODULE_NAME = void 0; -exports.CHANNEL_MODULE_NAME = '@vgerbot/channel'; -exports.DEFAULT_TRANSFORMER_OPTIONS = {}; -//# sourceMappingURL=consts.js.map \ No newline at end of file diff --git a/packages/transformer/lib/consts.js.map b/packages/transformer/lib/consts.js.map deleted file mode 100644 index f96752f..0000000 --- a/packages/transformer/lib/consts.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AACzC,QAAA,2BAA2B,GAAG,EAE1C,CAAC"} \ No newline at end of file diff --git a/packages/transformer/lib/index.d.ts b/packages/transformer/lib/index.d.ts deleted file mode 100644 index 5de6d1c..0000000 --- a/packages/transformer/lib/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import ts from 'typescript'; -import { TransformerOptions } from './TransformerOptions'; -export { TransformerOptions }; -export default channelTransformerFactory; -export declare function channelTransformerFactory(program: ts.Program, options?: Partial): ts.TransformerFactory; diff --git a/packages/transformer/lib/index.js b/packages/transformer/lib/index.js deleted file mode 100644 index 334142a..0000000 --- a/packages/transformer/lib/index.js +++ /dev/null @@ -1,208 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.channelTransformerFactory = void 0; -const tslib_1 = require("tslib"); -const consts_1 = require("./consts"); -const utils_1 = require("./utils"); -const typescript_1 = tslib_1.__importStar(require("typescript")); -const ChannelProgramContext_1 = require("./ChannelProgramContext"); -exports.default = channelTransformerFactory; -function channelTransformerFactory(program, options) { - const resolvedOptions = Object.assign(Object.assign({}, consts_1.DEFAULT_TRANSFORMER_OPTIONS), (options || {})); - return (context) => { - const channelSymbols = findChannelSymbols(program); - return (file) => { - if (!channelSymbols) { - return file; - } - const findChannelModule = file.statements.find(it => { - if (typescript_1.default.isImportDeclaration(it)) { - if (typescript_1.default.isStringLiteralLike(it.moduleSpecifier)) { - const moduleName = it.moduleSpecifier.text; - return moduleName === consts_1.CHANNEL_MODULE_NAME; - } - } - return false; - }); - if (!findChannelModule) { - return file; - } - const programCtx = new ChannelProgramContext_1.ChannelProgramContext(program.getTypeChecker(), channelSymbols); - const sourceFileNode = typescript_1.default.visitEachChild(file, visitor, context); - const variableDeclarations = Array.from(programCtx.variablesMap.values()); - const variableStatements = variableDeclarations.length > 0 ? [typescript_1.factory.createVariableStatement([], variableDeclarations)] : []; - return typescript_1.default.factory.updateSourceFile(sourceFileNode, [...variableStatements, ...sourceFileNode.statements]); - function visitor(node) { - const ret = visitNode(node, program, programCtx, context, resolvedOptions); - if (!ret) { - return typescript_1.default.visitEachChild(node, visitor, context); - } - else { - return ret; - } - } - }; - }; -} -exports.channelTransformerFactory = channelTransformerFactory; -function findChannelSymbols(program) { - const typeChecker = program.getTypeChecker(); - const channelFiles = program.getSourceFiles().filter(it => { - const fileSymbol = typeChecker.getSymbolAtLocation(it); - if (!fileSymbol) { - return false; - } - const symbolName = fileSymbol.getName(); - if (symbolName.indexOf('packages/core/dist') > -1) { - return true; - } - if (symbolName.indexOf('packages/core/src') > -1) { - return true; - } - if (symbolName.indexOf(consts_1.CHANNEL_MODULE_NAME) > -1) { - return true; - } - return false; - }); - let channelMethodSymbol; - let channelClassSymbol; - channelFiles.some(it => { - var _a, _b; - const fileSymbol = typeChecker.getSymbolAtLocation(it); - channelClassSymbol = channelClassSymbol || ((_a = fileSymbol === null || fileSymbol === void 0 ? void 0 : fileSymbol.exports) === null || _a === void 0 ? void 0 : _a.get('Channel')); - channelMethodSymbol = channelMethodSymbol || ((_b = fileSymbol === null || fileSymbol === void 0 ? void 0 : fileSymbol.exports) === null || _b === void 0 ? void 0 : _b.get('channel')); - return !!channelClassSymbol && !!channelMethodSymbol; - }); - if (channelClassSymbol && channelMethodSymbol) { - return { channelClassSymbol, channelMethodSymbol }; - } -} -function visitNode(node, program, programCtx, context, options) { - const variablesMap = programCtx.variablesMap; - const typeChecker = program.getTypeChecker(); - const factory = context.factory; - if (typescript_1.default.isImportDeclaration(node) && typescript_1.default.isStringLiteralLike(node.moduleSpecifier)) { - const moduleName = node.moduleSpecifier.text; - if (moduleName !== consts_1.CHANNEL_MODULE_NAME) { - return; - } - programCtx.recordChannelSymbolIfPossible(node); - } - else if (typescript_1.default.isVariableDeclaration(node)) { - programCtx.recordChannelVariableIfPossible(node); - } - else if (typescript_1.default.isBinaryExpression(node)) { - programCtx.recordChannelVariableByBinaryExpression(node); - } - else if (typescript_1.default.isCallExpression(node)) { - const propertyExpression = node.expression; - if (typescript_1.default.isPropertyAccessExpression(propertyExpression)) { - if (programCtx.isAccessingTheGetClassMethod(node, propertyExpression)) { - return handleGetClassMethod(node, typeChecker, factory, variablesMap); - } - else if (programCtx.isAccessingDefClassMethod(node, propertyExpression)) { - return handleDefClassMethod(node, typeChecker, options, factory); - } - else if (programCtx.isAccessingDefMethodMethod(node, propertyExpression)) { - return handleDefMethodMethod(node, factory); - } - } - } -} -function handleGetClassMethod(node, typeChecker, factory, variablesMap) { - const typeArgs = (0, utils_1.getTypeArguments)(node); - if (!typeArgs || typeArgs.length < 1) { - return; - } - const typeNode = typeArgs[0]; - const typeNodeObj = typeChecker.getTypeFromTypeNode(typeNode); - const typeNodeDeclaration = (0, utils_1.getTypeNodeDecration)(typeNodeObj); - if (!typeNodeDeclaration) { - return; - } - if (node.arguments.length > 1) { - return; - } - const classIdArg = node.arguments[0] || factory.createStringLiteral(typeNode.getText()); - let interfaceNode; - let memberNames; - if (typescript_1.default.isClassDeclaration(typeNodeDeclaration)) { - const modifiers = typeNodeDeclaration.modifiers; - const isAbstract = !!modifiers && modifiers.some(it => it.kind === typescript_1.default.SyntaxKind.AbstractKeyword); - if (!isAbstract) { - return factory.createCallExpression(node.expression, [], [classIdArg, factory.createRegularExpressionLiteral(typeNode.getText())]); - } - interfaceNode = typeChecker.getTypeAtLocation(typeNodeDeclaration); - memberNames = typeNodeDeclaration.members - .filter(it => !!it.name) - .map(it => { var _a; return (_a = it.name) === null || _a === void 0 ? void 0 : _a.getText(); }) - .filter(Boolean); - } - else { - interfaceNode = typeChecker.getTypeFromTypeNode(typeNode); - } - if (!interfaceNode) { - return; - } - let variable = variablesMap.get(interfaceNode); - if (!variable) { - if (!memberNames || memberNames.length === 0) { - memberNames = (0, utils_1.getMethodMembersFrom)(typeChecker, interfaceNode).map(it => it.getName()); - } - variable = variable || (0, utils_1.createMemberNamesvariable)(typeNode.getText() + 'Members', memberNames, factory); - variablesMap.set(interfaceNode, variable); - } - return factory.createCallExpression(node.expression, [], [classIdArg, variable.name]); -} -function handleDefClassMethod(node, typeChecker, options, factory) { - var _a; - const classIdentifier = node.arguments[0]; - const classSymbol = typeChecker.getSymbolAtLocation(classIdentifier); - if (!classSymbol) { - return; - } - let classId; - if (options.classIdStrategy === 'first-interface') { - const classDec = classSymbol.valueDeclaration; - if (classDec.heritageClauses && classDec.heritageClauses.length > 0) { - for (const clause of classDec.heritageClauses) { - const expression = (_a = clause.types[0]) === null || _a === void 0 ? void 0 : _a.expression; - const symbol = expression && typeChecker.getSymbolAtLocation(expression); - const declarations = symbol === null || symbol === void 0 ? void 0 : symbol.getDeclarations(); - const declaration = declarations ? declarations[0] : undefined; - if (!!symbol && !!declaration && typescript_1.default.isInterfaceDeclaration(declaration)) { - classId = symbol.getName(); - break; - } - } - } - } - else if (options.classIdStrategy === 'first-parent') { - const classDec = classSymbol.valueDeclaration; - if (classDec.heritageClauses && classDec.heritageClauses.length > 0) { - const firstHeritageClause = classDec.heritageClauses[0]; - const expression = firstHeritageClause === null || firstHeritageClause === void 0 ? void 0 : firstHeritageClause.types[0].expression; - const symbol = expression && typeChecker.getSymbolAtLocation(expression); - if (!!symbol) { - classId = symbol.getName(); - } - } - } - if (!classId) { - classId = classSymbol.getName(); - } - const classIdArg = factory.createStringLiteral(classId); - return factory.createCallExpression(node.expression, [], [classIdArg, classIdentifier]); -} -function handleDefMethodMethod(node, factory) { - const arg0 = node.arguments[0]; - if (typescript_1.default.isIdentifier(arg0)) { - const methodId = factory.createStringLiteral(arg0.text); - return factory.createCallExpression(node.expression, [], [methodId, arg0]); - } - else if (typescript_1.default.isFunctionExpression(arg0) && arg0.name) { - const methodId = factory.createStringLiteral(arg0.name.text); - return factory.createCallExpression(node.expression, [], [methodId, arg0]); - } -} -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/transformer/lib/index.js.map b/packages/transformer/lib/index.js.map deleted file mode 100644 index c3ea0d9..0000000 --- a/packages/transformer/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAA4E;AAC5E,mCAAkH;AAClH,iEAAyC;AACzC,mEAAgE;AAKhE,kBAAe,yBAAyB,CAAC;AAEzC,SAAgB,yBAAyB,CACrC,OAAmB,EACnB,OAAqC;IAErC,MAAM,eAAe,mCACd,oCAA2B,GAC3B,CAAC,OAAO,IAAI,EAAE,CAAC,CACrB,CAAC;IACF,OAAO,CAAC,OAAiC,EAAE,EAAE;QACzC,MAAM,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QACnD,OAAO,CAAC,IAAmB,EAAE,E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mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,OAAO,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9E;SAAM,IAAI,oBAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE;QACnD,MAAM,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,OAAO,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;KAC9E;AACL,CAAC"} \ No newline at end of file diff --git a/packages/transformer/lib/utils.d.ts b/packages/transformer/lib/utils.d.ts deleted file mode 100644 index fa70b50..0000000 --- a/packages/transformer/lib/utils.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import ts from 'typescript'; -export declare function getTypeNodeDecration(typeNodeObj: ts.Type): ts.Declaration | undefined; -export declare function createMemberNamesvariable(variableName: string, memberNames: string[], factory: ts.NodeFactory): ts.VariableDeclaration; -export declare function getMethodMembersFrom(typeChecker: ts.TypeChecker, typeNode: ts.Type): ts.Symbol[]; -export declare function getTypeArguments(node: ts.CallExpression): ts.NodeArray | undefined; diff --git a/packages/transformer/lib/utils.js b/packages/transformer/lib/utils.js deleted file mode 100644 index 22c4993..0000000 --- a/packages/transformer/lib/utils.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getTypeArguments = exports.getMethodMembersFrom = exports.createMemberNamesvariable = exports.getTypeNodeDecration = void 0; -const tslib_1 = require("tslib"); -const typescript_1 = tslib_1.__importDefault(require("typescript")); -function getTypeNodeDecration(typeNodeObj) { - var _a; - let declarations; - if (!!typeNodeObj.aliasSymbol) { - declarations = typeNodeObj.aliasSymbol.getDeclarations(); - } - else { - declarations = (_a = typeNodeObj.getSymbol()) === null || _a === void 0 ? void 0 : _a.getDeclarations(); - } - return declarations ? declarations[0] : undefined; -} -exports.getTypeNodeDecration = getTypeNodeDecration; -function createMemberNamesvariable(variableName, memberNames, factory) { - const memberNameLiterals = memberNames.map(it => { - return factory.createStringLiteral(it); - }); - const membersArrayExpression = factory.createArrayLiteralExpression(memberNameLiterals); - const membersVariableName = factory.createUniqueName(variableName); - return factory.createVariableDeclaration(membersVariableName, undefined, undefined, membersArrayExpression); -} -exports.createMemberNamesvariable = createMemberNamesvariable; -function getMethodMembersFrom(typeChecker, typeNode) { - const members = typeChecker.getPropertiesOfType(typeNode); - return members.filter(it => it.valueDeclaration !== undefined && typescript_1.default.isMethodSignature(it.valueDeclaration)); -} -exports.getMethodMembersFrom = getMethodMembersFrom; -function getTypeArguments(node) { - let typeArgs = node.typeArguments; - if (!typeArgs || typeArgs.length < 1) { - const original = node.original; - if (!!original && typescript_1.default.isCallExpression(original)) { - typeArgs = original.typeArguments; - } - } - return typeArgs; -} -exports.getTypeArguments = getTypeArguments; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/packages/transformer/lib/utils.js.map b/packages/transformer/lib/utils.js.map deleted file mode 100644 index ffc4650..0000000 --- a/packages/transformer/lib/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;AAAA,oEAA4B;AAE5B,SAAgB,oBAAoB,CAAC,WAAoB;;IACrD,IAAI,YAAY,CAAC;IACjB,IAAI,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE;QAC3B,YAAY,GAAG,WAAW,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;KAC5D;SAAM;QACH,YAAY,GAAG,MAAA,WAAW,CAAC,SAAS,EAAE,0CAAE,eAAe,EAAE,CAAC;KAC7D;IAED,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CA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;AATD,4CASC"} \ No newline at end of file diff --git a/packages/transformer/package.json b/packages/transformer/package.json deleted file mode 100644 index 742365f..0000000 --- a/packages/transformer/package.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "@vgerbot/channel-transformer", - "version": "1.0.1", - "description": "A typescript transformer which is used to simplify the use of the @vgerbot/channel", - "author": "y1j2x34 ", - "homepage": "https://github.com/y1j2x34/channel-ts/tree/master/packages/channel-ts-transformer#readme", - "license": "MIT", - "main": "lib/index.js", - "typings": "lib/index.d.ts", - "engine": { - "node": ">= 3.2.2" - }, - "keywords": [ - "channel", - "rmi", - "transformer", - "typescript", - "custom-transformer" - ], - "directories": { - "lib": "lib", - "test": "test" - }, - "files": [ - "lib" - ], - "publishConfig": { - "access": "public", - "registry": "https://registry.npmjs.org/" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/y1j2x34/channel-ts.git" - }, - "scripts": { - "test": "jest --coverage", - "debug": "node --inspect-brk node_modules/.bin/jest", - "lint": "eslint {src,test}/**/*.{ts,tsc}", - "format": "eslint --fix {src,test}/**/*.{ts,tsc}", - "build": "ttsc --project ./tsconfig.json", - "prepublish": "ttsc", - "codecov": "codecov -f ./coverage/cobertura-coverage.xml --flags '@vgerbot/channel-transformer'" - }, - "bugs": { - "url": "https://github.com/y1j2x34/channel-ts/issues" - }, - "devDependencies": { - "@types/jest": "^29.0.2", - "@types/node": "^18.7.18", - "@typescript-eslint/eslint-plugin": "^5.37.0", - "@typescript-eslint/parser": "^5.37.0", - "@typescript/vfs": "^1.4.0", - "@vgerbot/channel": "^1.0.1", - "codecov": "*", - "eslint": "8.22.0", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-prettier": "^4.2.1", - "husky": "8.0.1", - "jest": "^26.6.3", - "lint-staged": "^13.0.3", - "prettier": "^2.7.1", - "ts-jest": "^26.4.4", - "ts-node": "^10.9.1", - "tsconfig-paths": "^4.1.0", - "ttypescript": "^1.5.13", - "typescript": "4.9.5" - }, - "dependencies": { - "tslib": "^2.2.0" - }, - "peerDependencies": { - "typescript": ">=4.9.5" - } -} diff --git a/packages/transformer/src/ChannelProgramContext.ts b/packages/transformer/src/ChannelProgramContext.ts deleted file mode 100644 index c2dac1b..0000000 --- a/packages/transformer/src/ChannelProgramContext.ts +++ /dev/null @@ -1,170 +0,0 @@ -import ts from 'typescript'; -import { getTypeArguments } from './utils'; - -export interface ChannelSymbols { - channelMethodSymbol: ts.Symbol; - channelClassSymbol: ts.Symbol; -} - -export class ChannelProgramContext { - constructor(private readonly typeChecker: ts.TypeChecker, channelSymbols: ChannelSymbols) { - this.channelClassSymbols.add(channelSymbols.channelClassSymbol); - this.channelMethodSymbols.add(channelSymbols.channelMethodSymbol); - } - - public channelMethodSymbols = new Set(); - public channelClassSymbols = new Set(); - public variablesMap = new Map(); - public channel_variables = new Set(); - - isAccessingDefClassMethod( - callExpression: ts.CallExpression, - propertyExpression: ts.PropertyAccessExpression - ): boolean { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'def_class') { - return false; - } - const args = callExpression.arguments; - if (args.length !== 1) { - return false; - } - const argSymbol = this.typeChecker.getSymbolAtLocation(args[0]); - const declaration = argSymbol?.valueDeclaration; - return !!declaration && ts.isClassDeclaration(declaration); - } - isAccessingDefMethodMethod(callExpression: ts.CallExpression, propertyExpression: ts.PropertyAccessExpression) { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'def_method') { - return false; - } - const args = callExpression.arguments; - if (args.length !== 1) { - return false; - } - const expressionType = this.typeChecker.getTypeAtLocation(propertyExpression.expression); - if (expressionType && !this.isChannelClassSymbol(expressionType.getSymbol())) { - return false; - } - - if (ts.isArrowFunction(args[0])) { - throw new Error('The first function parameter of Channel.def_method cannot be anonymous'); - } - if (ts.isFunctionExpression(args[0])) { - const functionName = args[0].name; - if (!functionName) { - throw new Error('The first function parameter of Channel.def_method cannot be anonymous'); - } - return true; - } else if (ts.isIdentifier(args[0])) { - const symbol = this.typeChecker.getSymbolAtLocation(args[0]); - if (symbol) { - const declaration = symbol.declarations ? symbol.declarations[0] : undefined; - if (declaration && ts.isFunctionDeclaration(declaration)) { - return true; - } - } - } - return false; - } - - isAccessingTheGetClassMethod(callExpression: ts.CallExpression, propertyExpression: ts.PropertyAccessExpression) { - const propertyName = propertyExpression.name.text; - if (propertyName !== 'get_class') { - return false; - } - const typeArgs = getTypeArguments(callExpression); - if (!typeArgs || typeArgs.length < 1) { - return false; - } - const expressionType = this.typeChecker.getTypeAtLocation(propertyExpression.expression); - if (expressionType && this.isChannelClassSymbol(expressionType.getSymbol())) { - return true; - } - const LeftHandSideExpressionSymbol = this.typeChecker.getSymbolAtLocation(propertyExpression.expression); - return !!LeftHandSideExpressionSymbol && this.channel_variables.has(LeftHandSideExpressionSymbol); - } - - recordChannelVariableByBinaryExpression(node: ts.BinaryExpression) { - const typeChecker = this.typeChecker; - const variables = this.channel_variables; - - const variableSymbol = typeChecker.getSymbolAtLocation(node.left); - if (!variableSymbol) { - return; - } - if (this.isChannelInstanceInitializerExpression(node.right)) { - variables.add(variableSymbol); - } - } - - recordChannelVariableIfPossible(node: ts.VariableDeclaration) { - const typeChecker = this.typeChecker; - const variables = this.channel_variables; - const initializer = node.initializer; - if (!initializer) { - return; - } - const variableSymbol = typeChecker.getSymbolAtLocation(node.name); - if (!variableSymbol) { - return; - } - if (this.isChannelInstanceInitializerExpression(initializer)) { - variables.add(variableSymbol); - } - } - - private isChannelInstanceInitializerExpression(initializer: ts.Expression) { - const typeChecker = this.typeChecker; - if (ts.isNewExpression(initializer)) { - const classSymbol = typeChecker.getSymbolAtLocation(initializer.expression); - if (this.isChannelClassSymbol(classSymbol)) { - return true; - } - } else if (ts.isCallExpression(initializer)) { - let expression = initializer.expression; - while (true) { - if (ts.isCallExpression(expression)) { - expression = expression.expression; - } else if (ts.isPropertyAccessExpression(expression)) { - expression = expression.expression; - } else { - break; - } - } - if (ts.isIdentifier(expression)) { - const symbol = typeChecker.getSymbolAtLocation(expression); - if (this.isChannelMethodSymbol(symbol)) { - return true; - } - if (symbol) { - return this.channel_variables.has(symbol); - } - } - } - return false; - } - isChannelMethodSymbol(symbol: undefined | ts.Symbol): symbol is ts.Symbol { - return !!symbol && this.channelMethodSymbols.has(symbol); - } - isChannelClassSymbol(symbol: undefined | ts.Symbol): symbol is ts.Symbol { - return !!symbol && this.channelClassSymbols.has(symbol); - } - recordChannelSymbolIfPossible(node: ts.ImportDeclaration) { - const namedBindings = node.importClause?.namedBindings; - if (namedBindings && ts.isNamedImports(namedBindings)) { - const importElementsArray = namedBindings.elements.map(it => { - const name = it.propertyName ? it.propertyName.text : it.name.text; - return { name, importSpecifier: it, symbol: this.typeChecker.getSymbolAtLocation(it.name) }; - }); - const { symbol: channelMethodSymbol } = importElementsArray.find(it => it.name === 'channel') || {}; - if (channelMethodSymbol) { - this.channelMethodSymbols.add(channelMethodSymbol); - } - const { symbol: channelClassSymbol } = importElementsArray.find(it => it.name === 'Channel') || {}; - if (channelClassSymbol) { - this.channelClassSymbols.add(channelClassSymbol); - } - } - } -} diff --git a/packages/transformer/src/TransformerOptions.ts b/packages/transformer/src/TransformerOptions.ts deleted file mode 100644 index 31963b7..0000000 --- a/packages/transformer/src/TransformerOptions.ts +++ /dev/null @@ -1,4 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface TransformerOptions { - classIdStrategy: 'self' | 'first-interface' | 'first-parent'; -} diff --git a/packages/transformer/src/consts.ts b/packages/transformer/src/consts.ts deleted file mode 100644 index 748c92e..0000000 --- a/packages/transformer/src/consts.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const CHANNEL_MODULE_NAME = '@vgerbot/channel'; -export const DEFAULT_TRANSFORMER_OPTIONS = { - // EMPTY -}; diff --git a/packages/transformer/src/index.ts b/packages/transformer/src/index.ts deleted file mode 100644 index eff357e..0000000 --- a/packages/transformer/src/index.ts +++ /dev/null @@ -1,239 +0,0 @@ -import { CHANNEL_MODULE_NAME, DEFAULT_TRANSFORMER_OPTIONS } from './consts'; -import { createMemberNamesvariable, getMethodMembersFrom, getTypeArguments, getTypeNodeDecration } from './utils'; -import ts, { factory } from 'typescript'; -import { ChannelProgramContext } from './ChannelProgramContext'; -import { TransformerOptions } from './TransformerOptions'; - -export { TransformerOptions }; - -export default channelTransformerFactory; - -export function channelTransformerFactory( - program: ts.Program, - options?: Partial -): ts.TransformerFactory { - const resolvedOptions = { - ...DEFAULT_TRANSFORMER_OPTIONS, - ...(options || {}) - }; - return (context: ts.TransformationContext) => { - const channelSymbols = findChannelSymbols(program); - return (file: ts.SourceFile) => { - if (!channelSymbols) { - return file; - } - const findChannelModule = file.statements.find(it => { - if (ts.isImportDeclaration(it)) { - if (ts.isStringLiteralLike(it.moduleSpecifier)) { - const moduleName = it.moduleSpecifier.text; - return moduleName === CHANNEL_MODULE_NAME; - } - } - return false; - }); - - if (!findChannelModule) { - return file; - } - - const programCtx = new ChannelProgramContext(program.getTypeChecker(), channelSymbols); - - const sourceFileNode = ts.visitEachChild(file, visitor, context) as ts.SourceFile; - - const variableDeclarations = Array.from(programCtx.variablesMap.values()); - const variableStatements = - variableDeclarations.length > 0 ? [factory.createVariableStatement([], variableDeclarations)] : []; - return ts.factory.updateSourceFile(sourceFileNode, [...variableStatements, ...sourceFileNode.statements]); - - function visitor(node: ts.Node): ts.Node | Array { - const ret = visitNode(node, program, programCtx, context, resolvedOptions); - if (!ret) { - return ts.visitEachChild(node, visitor, context); - } else { - return ret; - } - } - }; - }; -} - -function findChannelSymbols(program: ts.Program) { - const typeChecker = program.getTypeChecker(); - const channelFiles = program.getSourceFiles().filter(it => { - const fileSymbol = typeChecker.getSymbolAtLocation(it); - if (!fileSymbol) { - return false; - } - const symbolName = fileSymbol.getName(); - if (symbolName.indexOf('packages/core/dist') > -1) { - return true; - } - if (symbolName.indexOf('packages/core/src') > -1) { - return true; - } - if (symbolName.indexOf(CHANNEL_MODULE_NAME) > -1) { - return true; - } - return false; - }); - let channelMethodSymbol: undefined | ts.Symbol; - let channelClassSymbol: undefined | ts.Symbol; - channelFiles.some(it => { - const fileSymbol = typeChecker.getSymbolAtLocation(it); - channelClassSymbol = channelClassSymbol || fileSymbol?.exports?.get('Channel' as ts.__String); - channelMethodSymbol = channelMethodSymbol || fileSymbol?.exports?.get('channel' as ts.__String); - return !!channelClassSymbol && !!channelMethodSymbol; - }); - if (channelClassSymbol && channelMethodSymbol) { - return { channelClassSymbol, channelMethodSymbol }; - } -} - -function visitNode( - node: ts.Node, - program: ts.Program, - programCtx: ChannelProgramContext, - context: ts.TransformationContext, - options: Partial -): undefined | ts.Node | Array { - const variablesMap = programCtx.variablesMap; - const typeChecker = program.getTypeChecker(); - const factory = context.factory; - if (ts.isImportDeclaration(node) && ts.isStringLiteralLike(node.moduleSpecifier)) { - const moduleName = node.moduleSpecifier.text; - if (moduleName !== CHANNEL_MODULE_NAME) { - return; - } - programCtx.recordChannelSymbolIfPossible(node); - } else if (ts.isVariableDeclaration(node)) { - programCtx.recordChannelVariableIfPossible(node); - } else if (ts.isBinaryExpression(node)) { - programCtx.recordChannelVariableByBinaryExpression(node); - } else if (ts.isCallExpression(node)) { - const propertyExpression = node.expression; - if (ts.isPropertyAccessExpression(propertyExpression)) { - if (programCtx.isAccessingTheGetClassMethod(node, propertyExpression)) { - return handleGetClassMethod(node, typeChecker, factory, variablesMap); - } else if (programCtx.isAccessingDefClassMethod(node, propertyExpression)) { - return handleDefClassMethod(node, typeChecker, options, factory); - } else if (programCtx.isAccessingDefMethodMethod(node, propertyExpression)) { - return handleDefMethodMethod(node, factory); - } - } - } -} - -function handleGetClassMethod( - node: ts.CallExpression, - typeChecker: ts.TypeChecker, - factory: ts.NodeFactory, - variablesMap: Map -) { - const typeArgs = getTypeArguments(node); - if (!typeArgs || typeArgs.length < 1) { - return; - } - - const typeNode = typeArgs[0]; - const typeNodeObj = typeChecker.getTypeFromTypeNode(typeNode); - - const typeNodeDeclaration = getTypeNodeDecration(typeNodeObj); - if (!typeNodeDeclaration) { - return; - } - if (node.arguments.length > 1) { - return; - } - - const classIdArg = node.arguments[0] || factory.createStringLiteral(typeNode.getText()); - - let interfaceNode: ts.Type; - let memberNames: undefined | string[]; - if (ts.isClassDeclaration(typeNodeDeclaration)) { - const modifiers = (typeNodeDeclaration as ts.ClassDeclaration).modifiers; - const isAbstract = !!modifiers && modifiers.some(it => it.kind === ts.SyntaxKind.AbstractKeyword); - if (!isAbstract) { - return factory.createCallExpression( - node.expression, - [], - [classIdArg, factory.createRegularExpressionLiteral(typeNode.getText())] - ); - } - interfaceNode = typeChecker.getTypeAtLocation(typeNodeDeclaration); - memberNames = typeNodeDeclaration.members - .filter(it => !!it.name) - .map(it => it.name?.getText()) - .filter(Boolean) as string[]; - } else { - interfaceNode = typeChecker.getTypeFromTypeNode(typeNode); - } - if (!interfaceNode) { - return; - } - let variable = variablesMap.get(interfaceNode); - if (!variable) { - if (!memberNames || memberNames.length === 0) { - memberNames = getMethodMembersFrom(typeChecker, interfaceNode).map(it => it.getName()); - } - variable = variable || createMemberNamesvariable(typeNode.getText() + 'Members', memberNames, factory); - variablesMap.set(interfaceNode, variable); - } - - return factory.createCallExpression(node.expression, [], [classIdArg, variable.name as ts.Identifier]); -} - -function handleDefClassMethod( - node: ts.CallExpression, - typeChecker: ts.TypeChecker, - options: Partial, - factory: ts.NodeFactory -) { - const classIdentifier = node.arguments[0] as ts.Identifier; - const classSymbol = typeChecker.getSymbolAtLocation(classIdentifier); - if (!classSymbol) { - return; - } - let classId!: string; - if (options.classIdStrategy === 'first-interface') { - const classDec = classSymbol.valueDeclaration as ts.ClassDeclaration; - if (classDec.heritageClauses && classDec.heritageClauses.length > 0) { - for (const clause of classDec.heritageClauses) { - const expression = clause.types[0]?.expression; - const symbol = expression && typeChecker.getSymbolAtLocation(expression); - const declarations = symbol?.getDeclarations(); - const declaration = declarations ? declarations[0] : undefined; - if (!!symbol && !!declaration && ts.isInterfaceDeclaration(declaration)) { - classId = symbol.getName(); - break; - } - } - } - } else if (options.classIdStrategy === 'first-parent') { - const classDec = classSymbol.valueDeclaration as ts.ClassDeclaration; - if (classDec.heritageClauses && classDec.heritageClauses.length > 0) { - const firstHeritageClause = classDec.heritageClauses[0]; - const expression = firstHeritageClause?.types[0].expression; - const symbol = expression && typeChecker.getSymbolAtLocation(expression); - if (!!symbol) { - classId = symbol.getName(); - } - } - } - - if (!classId) { - classId = classSymbol.getName(); - } - const classIdArg = factory.createStringLiteral(classId); - return factory.createCallExpression(node.expression, [], [classIdArg, classIdentifier]); -} - -function handleDefMethodMethod(node: ts.CallExpression, factory: ts.NodeFactory) { - const arg0 = node.arguments[0]; - if (ts.isIdentifier(arg0)) { - const methodId = factory.createStringLiteral(arg0.text); - return factory.createCallExpression(node.expression, [], [methodId, arg0]); - } else if (ts.isFunctionExpression(arg0) && arg0.name) { - const methodId = factory.createStringLiteral(arg0.name.text); - return factory.createCallExpression(node.expression, [], [methodId, arg0]); - } -} diff --git a/packages/transformer/src/utils.ts b/packages/transformer/src/utils.ts deleted file mode 100644 index 9ffd58e..0000000 --- a/packages/transformer/src/utils.ts +++ /dev/null @@ -1,40 +0,0 @@ -import ts from 'typescript'; - -export function getTypeNodeDecration(typeNodeObj: ts.Type) { - let declarations; - if (!!typeNodeObj.aliasSymbol) { - declarations = typeNodeObj.aliasSymbol.getDeclarations(); - } else { - declarations = typeNodeObj.getSymbol()?.getDeclarations(); - } - - return declarations ? declarations[0] : undefined; -} - -export function createMemberNamesvariable(variableName: string, memberNames: string[], factory: ts.NodeFactory) { - const memberNameLiterals = memberNames.map(it => { - return factory.createStringLiteral(it); - }); - - const membersArrayExpression = factory.createArrayLiteralExpression(memberNameLiterals); - - const membersVariableName = factory.createUniqueName(variableName); - - return factory.createVariableDeclaration(membersVariableName, undefined, undefined, membersArrayExpression); -} - -export function getMethodMembersFrom(typeChecker: ts.TypeChecker, typeNode: ts.Type) { - const members = typeChecker.getPropertiesOfType(typeNode); - return members.filter(it => it.valueDeclaration !== undefined && ts.isMethodSignature(it.valueDeclaration)); -} - -export function getTypeArguments(node: ts.CallExpression) { - let typeArgs = node.typeArguments; - if (!typeArgs || typeArgs.length < 1) { - const original = (node as any).original; - if (!!original && ts.isCallExpression(original)) { - typeArgs = original.typeArguments; - } - } - return typeArgs; -} diff --git a/packages/transformer/test/common/compiler.ts b/packages/transformer/test/common/compiler.ts deleted file mode 100644 index 214cb16..0000000 --- a/packages/transformer/test/common/compiler.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* istanbul ignore file */ -import { createSystem, createVirtualCompilerHost } from '@typescript/vfs'; -import { TransformerOptions } from '../../src'; -import fs from 'fs'; -import globby from 'globby'; -import path from 'path'; -import ts from 'typescript'; - -export type TSChannelTransformerType = ( - program: ts.Program, - options?: Partial -) => ts.TransformerFactory; - -const compilerOptions: ts.CompilerOptions = { - module: ts.ModuleKind.CommonJS, - moduleResolution: ts.ModuleResolutionKind.Classic, - target: ts.ScriptTarget.ESNext, - strict: true, - sourceMap: false, - importHelpers: false, - esModuleInterop: true, - skipLibCheck: false, - noImplicitAny: true, - include: '/', - baseUrl: path.resolve(__dirname, '../'), - paths: { - '@vgerbot/channel': [path.resolve(__dirname, '../../../core/dist/index')] - } -}; - -export type TranspileOptions = { - options?: ts.CompilerOptions; - channelTransformer?: TSChannelTransformerType; - channelTransformerOptions?: Partial; - transformers?: Array>; -}; - -export function transpile(filepath: string, code: string, transpileOptions: TranspileOptions): string { - const options = Object.assign({}, compilerOptions, transpileOptions.options || {}); - options.suppressOutputPathCheck = true; - options.allowNonTsExtensions = true; - - const fsMap = new Map(); - fsMap.set(filepath, code); - fsMap.set('/lib.esnext.full.d.ts', ' '); - - const basedir = path.resolve(__dirname, '../../../core/dist'); - const files = globby.sync(path.resolve(basedir, '**/*'), { - ignore: ['index.*.js'] - }); - files.forEach(it => { - const code = fs.readFileSync(it).toString('utf8'); - fsMap.set(it, code); - }); - - const system = createSystem(fsMap); - const host = createVirtualCompilerHost(system, options, ts); - - host.compilerHost.resolveModuleNames = ( - moduleNames: string[], - containingFile: string, - reusedNames: string[] | undefined, - redirectedReference: ts.ResolvedProjectReference | undefined, - options: ts.CompilerOptions - ): (ts.ResolvedModule | undefined)[] => { - return moduleNames - .map(moduleName => { - const result = ts.resolveModuleName(moduleName, containingFile, options, { - fileExists(fileName) { - return fsMap.has(fileName) || ts.sys.fileExists(fileName); - }, - readFile(fileName) { - return fsMap.get(fileName) || ts.sys.readFile(fileName) || ''; - } - }); - return result.resolvedModule; - }) - .filter(Boolean); - }; - const program = ts.createProgram({ - rootNames: [filepath], - options, - host: host.compilerHost - }); - - const transformers: Array> = []; - if (transpileOptions.transformers) { - transformers.push(...transpileOptions.transformers); - } - if (transpileOptions.channelTransformer) { - transformers.push(transpileOptions.channelTransformer(program, transpileOptions.channelTransformerOptions)); - } - // console.info(program.getSourceFiles()); - program.emit( - /*targetSourceFile*/ undefined, - /*writeFile*/ undefined, - /*cancellationToken*/ undefined, - /*emitOnlyDtsFiles*/ undefined, - { - before: transformers - } - ); - return fsMap.get(filepath.replace(/\.ts$/, '.js')) || ''; -} diff --git a/packages/transformer/test/common/load-fixture.ts b/packages/transformer/test/common/load-fixture.ts deleted file mode 100644 index 7d1f95c..0000000 --- a/packages/transformer/test/common/load-fixture.ts +++ /dev/null @@ -1,54 +0,0 @@ -import fs from 'fs'; -import path from 'path'; - -const FIXTURES_DIR_PATH = path.resolve(__dirname, '../fixtures'); - -export interface Fixture { - filepath: string; - source: string; -} - -export function loadFixtureByRelPath(relpath: string): Fixture { - const filepath = `fixtures/${relpath}`; - const source = fs.readFileSync(path.resolve(FIXTURES_DIR_PATH, relpath)).toString('utf8'); - return { - filepath, - source - }; -} - -export function loadSpecialFixtures(filename: string): Fixture { - const relpath = `special/${filename}.ts`; - return loadFixtureByRelPath(relpath); -} - -export function loadFixtures(): Fixture[] { - const fixtureFiles = listDirTree(FIXTURES_DIR_PATH, (rootdir: string, relpath) => { - return relpath !== 'special'; - }); - return fixtureFiles.map(it => loadFixtureByRelPath(it.rpath)); -} - -function listDirTree(rootdir: string, filter: (rootdir: string, relpath: string) => boolean) { - const paths: Array<{ abspath: string; rpath: string }> = []; - function _listDirTree(curpath: string, relpath: string) { - fs.readdirSync(curpath).forEach(fitem => { - const rpath = relpath === '' ? fitem : relpath + path.sep + fitem; - if (!filter(rootdir, rpath)) { - return; - } - const abspath = path.resolve(rootdir, rpath); - if (fs.statSync(abspath).isDirectory()) { - _listDirTree(abspath, rpath); - } else { - paths.push({ - abspath, - rpath - }); - } - }); - } - - _listDirTree(rootdir, ''); - return paths; -} diff --git a/packages/transformer/test/fixtures/abstract class.ts b/packages/transformer/test/fixtures/abstract class.ts deleted file mode 100644 index ba7ae8a..0000000 --- a/packages/transformer/test/fixtures/abstract class.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); -abstract class RemoteAPI { - method(){} - abstract method2(); -} diff --git a/packages/transformer/test/fixtures/autofill parameters.ts b/packages/transformer/test/fixtures/autofill parameters.ts deleted file mode 100644 index eace819..0000000 --- a/packages/transformer/test/fixtures/autofill parameters.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -interface RemoteAPI { - method(); -} -channel.get_class(); diff --git a/packages/transformer/test/fixtures/automatic method id.ts b/packages/transformer/test/fixtures/automatic method id.ts deleted file mode 100644 index d833e96..0000000 --- a/packages/transformer/test/fixtures/automatic method id.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -c.def_method(function hello() {}) - -const a = () => {}; -c.def_method( a) - -const b = function () {}; - -c.def_method(b) diff --git a/packages/transformer/test/fixtures/channel builder.ts b/packages/transformer/test/fixtures/channel builder.ts deleted file mode 100644 index 9ede876..0000000 --- a/packages/transformer/test/fixtures/channel builder.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -interface RemoteAPI { - method(); -} - -c.get_class(); diff --git a/packages/transformer/test/fixtures/def class.ts b/packages/transformer/test/fixtures/def class.ts deleted file mode 100644 index b288d7c..0000000 --- a/packages/transformer/test/fixtures/def class.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -interface RemoteAPI { - method(); -} - -class AA {} - -class RemoteAPIImpl extends AA implements RemoteAPI { - method() {} -} - -c.def_class(RemoteAPIImpl); // same as - -c.def_class('RemoteAPIImpl', RemoteAPIImpl) diff --git a/packages/transformer/test/fixtures/interface parameter.ts b/packages/transformer/test/fixtures/interface parameter.ts deleted file mode 100644 index 7def55b..0000000 --- a/packages/transformer/test/fixtures/interface parameter.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); -interface RemoteAPI { - method(): void; -} diff --git a/packages/transformer/test/fixtures/intersection type.ts b/packages/transformer/test/fixtures/intersection type.ts deleted file mode 100644 index a16af1b..0000000 --- a/packages/transformer/test/fixtures/intersection type.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -type RemoteAPI1 = { - method1(): void; -}; -type RemoteAPI2 = { - method2(): void; - method3(): void; -}; -type RemoteAPI = RemoteAPI1 & RemoteAPI2; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); diff --git a/packages/transformer/test/fixtures/special/alias.ts b/packages/transformer/test/fixtures/special/alias.ts deleted file mode 100644 index 5733972..0000000 --- a/packages/transformer/test/fixtures/special/alias.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Channel as ChannelAlias } from '@vgerbot/channel'; -const channel = new ChannelAlias(); -channel.get_class(); -interface RemoteAPI { - method(): void; -} diff --git a/packages/transformer/test/fixtures/special/class id strategy first-interface.ts b/packages/transformer/test/fixtures/special/class id strategy first-interface.ts deleted file mode 100644 index c38ac8f..0000000 --- a/packages/transformer/test/fixtures/special/class id strategy first-interface.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -interface RemoteAPI { - method(); -} - -class AA {} - -class RemoteAPIImpl extends AA implements RemoteAPI { - method() {} -} - -c.def_class(RemoteAPIImpl); - -// ↑ same as ↓ - -c.def_class('RemoteAPI', RemoteAPIImpl) diff --git a/packages/transformer/test/fixtures/special/class id strategy first-parent.ts b/packages/transformer/test/fixtures/special/class id strategy first-parent.ts deleted file mode 100644 index 7ae6a37..0000000 --- a/packages/transformer/test/fixtures/special/class id strategy first-parent.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -interface RemoteAPI { - method(); -} - -class AA {} - -class RemoteAPIImpl extends AA implements RemoteAPI { - method() {} -} - -c.def_class(RemoteAPIImpl); - -// ↑ same as ↓ - -c.def_class('AA', RemoteAPIImpl) diff --git a/packages/transformer/test/fixtures/special/detect anonymous arrow functions.ts b/packages/transformer/test/fixtures/special/detect anonymous arrow functions.ts deleted file mode 100644 index 0011e24..0000000 --- a/packages/transformer/test/fixtures/special/detect anonymous arrow functions.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -c.def_method(() => {}) diff --git a/packages/transformer/test/fixtures/special/detect anonymous functions.ts b/packages/transformer/test/fixtures/special/detect anonymous functions.ts deleted file mode 100644 index da81998..0000000 --- a/packages/transformer/test/fixtures/special/detect anonymous functions.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { channel } from '@vgerbot/channel'; -let channelBuilder = channel("channel-id"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); - -c.def_method(function () {}) diff --git a/packages/transformer/test/fixtures/special/exclude 2 arguments.ts b/packages/transformer/test/fixtures/special/exclude 2 arguments.ts deleted file mode 100644 index 768b9e2..0000000 --- a/packages/transformer/test/fixtures/special/exclude 2 arguments.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Channel as ChannelAlias, WebWorkerScopeCommunicator } from '@vgerbot/channel'; - -const channel = new ChannelAlias('', new WebWorkerScopeCommunicator()); - -channel.get_class('RemoteAPI1', class { - method(){} -}); - -interface RemoteAPI { - method(): void -} diff --git a/packages/transformer/test/fixtures/special/exclude without type arguments.ts b/packages/transformer/test/fixtures/special/exclude without type arguments.ts deleted file mode 100644 index f94aee5..0000000 --- a/packages/transformer/test/fixtures/special/exclude without type arguments.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; - -const channel = new Channel('', new WebWorkerScopeCommunicator()); - -channel.get_class('RemoteAPI', class RemoteAPI { - method(){} -}); diff --git a/packages/transformer/test/fixtures/special/normal.ts b/packages/transformer/test/fixtures/special/normal.ts deleted file mode 100644 index 10fcc5a..0000000 --- a/packages/transformer/test/fixtures/special/normal.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { Channel } from '@vgerbot/channel'; -export let x: string = 'string'; -console.info(Channel); diff --git a/packages/transformer/test/fixtures/special/reference class.ts b/packages/transformer/test/fixtures/special/reference class.ts deleted file mode 100644 index f45ff89..0000000 --- a/packages/transformer/test/fixtures/special/reference class.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); -class RemoteAPI { - method(){} -} diff --git a/packages/transformer/test/fixtures/special/reuse converted variables.ts b/packages/transformer/test/fixtures/special/reuse converted variables.ts deleted file mode 100644 index 4b789d2..0000000 --- a/packages/transformer/test/fixtures/special/reuse converted variables.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); -channel.get_class(); -abstract class RemoteAPI { - method() {}; - abstract method2(); -} -function scope_a() { - channel.get_class(); - channel.get_class(); - interface RemoteAPI { - method(); - } - function scope_inner_a() { - channel.get_class(); - channel.get_class(); - interface InnerRemoteAPI { - method(); - } - } -} diff --git a/packages/transformer/test/fixtures/type statement.ts b/packages/transformer/test/fixtures/type statement.ts deleted file mode 100644 index 7cc7c35..0000000 --- a/packages/transformer/test/fixtures/type statement.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -type RemoteAPI = { - method(); -}; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); diff --git a/packages/transformer/test/fixtures/union type.ts b/packages/transformer/test/fixtures/union type.ts deleted file mode 100644 index d134b33..0000000 --- a/packages/transformer/test/fixtures/union type.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Channel, WebWorkerScopeCommunicator } from '@vgerbot/channel'; -interface RemoteAPI1 { - method1(): void; -} -interface RemoteAPI1 { - method1x(): void; -} -interface RemoteAPI2 { - method2(): void; - method3(): void; -} -type RemoteAPI = RemoteAPI1 & RemoteAPI2; -const channel = new Channel('', new WebWorkerScopeCommunicator()); -channel.get_class(); diff --git a/packages/transformer/test/specs/__snapshots__/index.spec.ts.snap b/packages/transformer/test/specs/__snapshots__/index.spec.ts.snap deleted file mode 100644 index 21c2f7d..0000000 --- a/packages/transformer/test/specs/__snapshots__/index.spec.ts.snap +++ /dev/null @@ -1,221 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`@vgerbot/channel-transformer should be able to detect the module alias 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel(); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should be able to exclude methods calling that has more than 2 arguments 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class('RemoteAPI1', class { - method() { } -}); -" -`; - -exports[`@vgerbot/channel-transformer should be able to exclude methods without type arguments 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class('RemoteAPI', class RemoteAPI { - method() { } -}); -" -`; - -exports[`@vgerbot/channel-transformer should be able to reference the class 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPI); -class RemoteAPI { - method() { } -} -" -`; - -exports[`@vgerbot/channel-transformer should reuse converted variables 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\", \\"method2\\"], RemoteAPIMembers_2 = [\\"method\\"], InnerRemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -class RemoteAPI { - method() { } - ; -} -function scope_a() { - channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_2); - channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_2); - function scope_inner_a() { - channel.get_class(\\"InnerRemoteAPI\\", InnerRemoteAPIMembers_1); - channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_2); - } -} -" -`; - -exports[`@vgerbot/channel-transformer should run normally with the transformer 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -exports.x = void 0; -const channel_1 = require(\\"@vgerbot/channel\\"); -exports.x = 'string'; -console.info(channel_1.Channel); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/abstract class.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\", \\"method2\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -class RemoteAPI { - method() { } -} -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/autofill parameters.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/automatic method id.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -let channelBuilder = (0, channel_1.channel)(\\"channel-id\\"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); -c.def_method(\\"hello\\", function hello() { }); -const a = () => { }; -c.def_method(a); -const b = function () { }; -c.def_method(b); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/channel builder.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -let channelBuilder = (0, channel_1.channel)(\\"channel-id\\"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); -c.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/def class.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -let channelBuilder = (0, channel_1.channel)(\\"channel-id\\"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); -class AA { -} -class RemoteAPIImpl extends AA { - method() { } -} -c.def_class(\\"RemoteAPIImpl\\", RemoteAPIImpl); // same as -c.def_class('RemoteAPIImpl', RemoteAPIImpl); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/interface parameter.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/intersection type.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method1\\", \\"method2\\", \\"method3\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/type statement.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should transform "fixtures/union type.ts" correctly 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -var RemoteAPIMembers_1 = [\\"method1\\", \\"method1x\\", \\"method2\\", \\"method3\\"]; -const channel_1 = require(\\"@vgerbot/channel\\"); -const channel = new channel_1.Channel('', new channel_1.WebWorkerScopeCommunicator()); -channel.get_class(\\"RemoteAPI\\", RemoteAPIMembers_1); -" -`; - -exports[`@vgerbot/channel-transformer should use the name of the first parent class as the class id 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -let channelBuilder = (0, channel_1.channel)(\\"channel-id\\"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); -class AA { -} -class RemoteAPIImpl extends AA { - method() { } -} -c.def_class(\\"AA\\", RemoteAPIImpl); -// ↑ same as ↓ -c.def_class('AA', RemoteAPIImpl); -" -`; - -exports[`@vgerbot/channel-transformer should use the name of the first parent interface as the class id 1`] = ` -"\\"use strict\\"; -Object.defineProperty(exports, \\"__esModule\\", { value: true }); -const channel_1 = require(\\"@vgerbot/channel\\"); -let channelBuilder = (0, channel_1.channel)(\\"channel-id\\"); -let generator = channelBuilder.connectToMainThread(); -const c = generator.create(); -class AA { -} -class RemoteAPIImpl extends AA { - method() { } -} -c.def_class(\\"RemoteAPI\\", RemoteAPIImpl); -// ↑ same as ↓ -c.def_class('RemoteAPI', RemoteAPIImpl); -" -`; diff --git a/packages/transformer/test/specs/index.spec.ts b/packages/transformer/test/specs/index.spec.ts deleted file mode 100644 index a7df5a2..0000000 --- a/packages/transformer/test/specs/index.spec.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { TransformerOptions, channelTransformerFactory } from '../../src'; -import { loadFixtures, loadSpecialFixtures } from '../common/load-fixture'; -import { transpile } from '../common/compiler'; - -interface TestCase { - source: string; - filepath: string; - name: string; - only?: boolean; - skip?: boolean; - shouldThrow?: boolean | string; - transformerOptions?: Partial; -} - -interface SpecialFixture { - file: string; - name: string; - only?: boolean; - skip?: boolean; - shouldThrow?: boolean | string; - transformerOptions?: Partial; -} - -describe('@vgerbot/channel-transformer', () => { - const specialFixtures: SpecialFixture[] = [ - { - file: 'normal', - name: 'should run normally with the transformer' - }, - { - file: 'alias', - name: 'should be able to detect the module alias' - }, - { - file: 'exclude 2 arguments', - name: 'should be able to exclude methods calling that has more than 2 arguments' - }, - { - file: 'exclude without type arguments', - name: 'should be able to exclude methods without type arguments' - }, - { - file: 'reference class', - name: 'should be able to reference the class' - }, - { - file: 'reuse converted variables', - name: 'should reuse converted variables' - }, - { - file: 'class id strategy first-interface', - name: 'should use the name of the first parent interface as the class id', - transformerOptions: { - classIdStrategy: 'first-interface' - } - }, - { - file: 'class id strategy first-parent', - name: 'should use the name of the first parent class as the class id', - transformerOptions: { - classIdStrategy: 'first-parent' - } - }, - { - file: 'detect anonymous arrow functions', - name: 'should throw when passing a anonymous arrow function to Channel.def_method', - shouldThrow: 'The first function parameter of Channel.def_method cannot be anonymous' - }, - { - file: 'detect anonymous functions', - name: 'should throw when passing a anonymous function to Channel.def_method', - shouldThrow: 'The first function parameter of Channel.def_method cannot be anonymous' - } - ]; - - specialFixtures - .map(it => { - return { - ...it, - source: loadSpecialFixtures(it.file).source, - filepath: `fixtures/special/${it.file}.ts` - } as TestCase; - }) - .concat( - loadFixtures().map(it => { - return { - ...it, - name: `should transform "${it.filepath}" correctly`, - // only: it.filepath.indexOf('automatic method id') > -1, - only: false, - skip: false - }; - }) - ) - .forEach(({ filepath, source, name, only, skip, transformerOptions, shouldThrow }) => { - let callback: jest.ProvidesCallback = () => { - const output = transpile(filepath, source, { - channelTransformer: channelTransformerFactory, - channelTransformerOptions: transformerOptions - }); - expect(output).toMatchSnapshot(); - }; - if (shouldThrow) { - const test_case = callback; - if (typeof shouldThrow === 'string') { - callback = () => { - expect(test_case).toThrowError(shouldThrow); - }; - } else { - callback = () => { - expect(test_case).toThrow(); - }; - } - } - if (only) { - it.only(name, callback); - } else if (skip) { - it.skip(name, callback); - } else { - it(name, callback); - } - }); -}); diff --git a/packages/transformer/test/tsconfig.json b/packages/transformer/test/tsconfig.json deleted file mode 100644 index f385747..0000000 --- a/packages/transformer/test/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "declaration": false, - "sourceMap": true, - "outDir": "../test_dist" - }, - "include": [ - "./specs" - ] -} diff --git a/packages/transformer/tsconfig.json b/packages/transformer/tsconfig.json deleted file mode 100644 index 72ff460..0000000 --- a/packages/transformer/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "module": "CommonJS", - "moduleResolution": "Node", - "target": "ES6", - "lib": ["ESNext"], - "strict": true, - "noImplicitAny": true, - "noUnusedLocals": true, - "removeComments": true, - "sourceMap": true, - "importHelpers": true, - "esModuleInterop": true, - "declaration": true, - "outDir": "./lib", - "skipLibCheck": true - }, - "include": ["src"] -} diff --git a/scripts/build.mjs b/scripts/build.mjs index 5420ee0..32f85a6 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,10 +1,9 @@ -import { getWorkspaceName } from './workspace-name.mjs'; +import { getWorkspaceName } from "./workspace-name.mjs"; const workspaceName = getWorkspaceName(); -if(workspaceName !== 'all') { - await $`yarn workspace ${workspaceName} build` +if (workspaceName !== "all") { + await $`yarn workspace ${workspaceName} build`; } else { - await $`yarn workspace @vgerbot/channel build` - await $`yarn workspace @vgerbot/channel-transformer build` + await $`yarn workspace @vgerbot/channel build`; } diff --git a/scripts/run.mjs b/scripts/run.mjs index 503b0a6..a49aeb5 100644 --- a/scripts/run.mjs +++ b/scripts/run.mjs @@ -1,12 +1,11 @@ -import { getWorkspaceName } from './workspace-name.mjs'; +import { getWorkspaceName } from "./workspace-name.mjs"; const command = argv._[0]; const workspaceName = getWorkspaceName(1); -if(workspaceName !== 'all') { +if (workspaceName !== "all") { await $`yarn workspace ${workspaceName} ${command}`; } else { await $`yarn workspace @vgerbot/channel ${command}`; - await $`yarn workspace @vgerbot/channel-transformer ${command}`; } diff --git a/scripts/workspace-name.mjs b/scripts/workspace-name.mjs index a30a5ca..d10cd3a 100644 --- a/scripts/workspace-name.mjs +++ b/scripts/workspace-name.mjs @@ -1,12 +1,10 @@ -import 'zx/globals'; +import "zx/globals"; export function getWorkspaceName(argvIndex = 1) { switch (argv._[argvIndex]) { - case 'core': - return '@vgerbot/channel'; - case 'transformer': - return '@vgerbot/channel-transformer' + case "core": + return "@vgerbot/channel"; default: - return 'all' + return "all"; } }