diff --git a/package.json b/package.json index 90c71bd..abe71c4 100644 --- a/package.json +++ b/package.json @@ -62,8 +62,8 @@ "@typescript-eslint/eslint-plugin": "^4.25.0", "@typescript-eslint/parser": "^4.25.0", "@wessberg/rollup-plugin-ts": "^1.3.14", - "sandhog": "^1.0.40", - "@wessberg/ts-config": "^1.1.0", + "sandhog": "^1.0.41", + "@wessberg/ts-config": "^1.1.2", "ava": "^3.15.0", "eslint": "^7.27.0", "semver": "7.3.5", @@ -72,11 +72,11 @@ "eslint-plugin-jsdoc": "^35.0.0", "husky": "^6.0.0", "np": "7.5.0", - "pnpm": "^6.4.0", + "pnpm": "^6.6.1", "prettier": "^2.3.0", "pretty-quick": "^3.1.0", "rimraf": "^3.0.2", - "rollup": "^2.50.1", + "rollup": "^2.50.3", "standard-changelog": "^2.0.27", "ts-node": "^10.0.0", "typescript": "^4.3.2", @@ -101,8 +101,9 @@ "fast-glob": "^3.2.5", "reserved-words": "^0.1.2", "resolve": "^1.20.0", - "helpertypes": "^0.0.1", - "crosspath": "^0.0.8" + "helpertypes": "^0.0.2", + "crosspath": "^0.0.8", + "compatfactory": "^0.0.1" }, "peerDependencies": { "typescript": ">=3.2.x || >= 4.x" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c6c9e3..c36c7c5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,29 +11,30 @@ specifiers: "@typescript-eslint/parser": ^4.25.0 "@wessberg/rollup-plugin-ts": ^1.3.14 "@wessberg/stringutil": ^1.0.19 - "@wessberg/ts-config": ^1.1.0 + "@wessberg/ts-config": ^1.1.2 ava: ^3.15.0 chalk: ^4.1.1 commander: ^7.2.0 + compatfactory: ^0.0.1 crosspath: ^0.0.8 eslint: ^7.27.0 eslint-config-prettier: ^8.3.0 eslint-plugin-import: ^2.23.3 eslint-plugin-jsdoc: ^35.0.0 fast-glob: ^3.2.5 - helpertypes: ^0.0.1 + helpertypes: ^0.0.2 husky: ^6.0.0 memfs: ^3.2.2 np: 7.5.0 npm-check-updates: ^11.5.13 - pnpm: ^6.4.0 + pnpm: ^6.6.1 prettier: ^2.3.0 pretty-quick: ^3.1.0 reserved-words: ^0.1.2 resolve: ^1.20.0 rimraf: ^3.0.2 - rollup: ^2.50.1 - sandhog: ^1.0.40 + rollup: ^2.50.3 + sandhog: ^1.0.41 semver: 7.3.5 standard-changelog: ^2.0.27 ts-node: ^10.0.0 @@ -54,14 +55,15 @@ dependencies: "@wessberg/stringutil": 1.0.19 chalk: 4.1.1 commander: 7.2.0 + compatfactory: 0.0.1_typescript@4.3.2 crosspath: 0.0.8 fast-glob: 3.2.5 - helpertypes: 0.0.1 + helpertypes: 0.0.2 reserved-words: 0.1.2 resolve: 1.20.0 devDependencies: - "@rollup/plugin-node-resolve": 13.0.0_rollup@2.50.1 + "@rollup/plugin-node-resolve": 13.0.0_rollup@2.50.3 "@types/node": 15.6.1 "@types/prettier": 2.2.3 "@types/reserved-words": 0.1.0 @@ -69,8 +71,8 @@ devDependencies: "@types/semver": 7.3.6 "@typescript-eslint/eslint-plugin": 4.25.0_ec7770e83475322b368bff30b543badb "@typescript-eslint/parser": 4.25.0_eslint@7.27.0+typescript@4.3.2 - "@wessberg/rollup-plugin-ts": 1.3.14_rollup@2.50.1+typescript@4.3.2 - "@wessberg/ts-config": 1.1.0 + "@wessberg/rollup-plugin-ts": 1.3.14_rollup@2.50.3+typescript@4.3.2 + "@wessberg/ts-config": 1.1.2 ava: 3.15.0 eslint: 7.27.0 eslint-config-prettier: 8.3.0_eslint@7.27.0 @@ -80,12 +82,12 @@ devDependencies: memfs: 3.2.2 np: 7.5.0 npm-check-updates: 11.5.13 - pnpm: 6.4.0 + pnpm: 6.6.1 prettier: 2.3.0 pretty-quick: 3.1.0_prettier@2.3.0 rimraf: 3.0.2 - rollup: 2.50.1 - sandhog: 1.0.40 + rollup: 2.50.3 + sandhog: 1.0.41 semver: 7.3.5 standard-changelog: 2.0.27 ts-node: 10.0.0_b89ec6c4eb73802631cbe54606dd8cdb @@ -115,8 +117,8 @@ packages: "@babel/highlight": 7.14.0 dev: true - /@babel/compat-data/7.14.0: - resolution: {integrity: sha512-vu9V3uMM/1o5Hl5OekMUowo3FqXLJSw+s+66nt0fSWVWTtmosdzn45JHOB3cPtZoe6CTBDzvSw0RdOY85Q37+Q==} + /@babel/compat-data/7.14.4: + resolution: {integrity: sha512-i2wXrWQNkH6JplJQGn3Rd2I4Pij8GdHkXwHMxm+zV5YG/Jci+bCNrWZEWC4o+umiDkRrRs4dVzH3X4GP7vyjQQ==} dev: true /@babel/core/7.14.3: @@ -125,13 +127,13 @@ packages: dependencies: "@babel/code-frame": 7.12.13 "@babel/generator": 7.14.3 - "@babel/helper-compilation-targets": 7.13.16_@babel+core@7.14.3 + "@babel/helper-compilation-targets": 7.14.4_@babel+core@7.14.3 "@babel/helper-module-transforms": 7.14.2 "@babel/helpers": 7.14.0 - "@babel/parser": 7.14.3 + "@babel/parser": 7.14.4 "@babel/template": 7.12.13 "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 convert-source-map: 1.7.0 debug: 4.3.1 gensync: 1.0.0-beta.2 @@ -145,7 +147,7 @@ packages: /@babel/generator/7.14.3: resolution: {integrity: sha512-bn0S6flG/j0xtQdz3hsjJ624h3W0r3llttBMfyHX3YrZ/KtLYr15bjA0FXkgW7FpvrDuTuElXeVjiKlYRpnOFA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 jsesc: 2.5.2 source-map: 0.5.7 dev: true @@ -153,30 +155,30 @@ packages: /@babel/helper-annotate-as-pure/7.12.13: resolution: {integrity: sha512-7YXfX5wQ5aYM/BOlbSccHDbuXXFPxeoUmfWtz8le2yTkTZc+BxsiEnENFoi2SlmA8ewDkG2LgIMIVzzn2h8kfw==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-builder-binary-assignment-operator-visitor/7.12.13: resolution: {integrity: sha512-CZOv9tGphhDRlVjVkAgm8Nhklm9RzSmWpX2my+t7Ua/KT616pEzXsQCjinzvkRvHWJ9itO4f296efroX23XCMA==} dependencies: "@babel/helper-explode-assignable-expression": 7.13.0 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true - /@babel/helper-compilation-targets/7.13.16_@babel+core@7.14.3: - resolution: {integrity: sha512-3gmkYIrpqsLlieFwjkGgLaSHmhnvlAYzZLlYVjlW+QwI+1zE17kGxuJGmIqDQdYp56XdmGeD+Bswx0UTyG18xA==} + /@babel/helper-compilation-targets/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-JgdzOYZ/qGaKTVkn5qEDV/SXAh8KcyUVkCoSWGN8T3bwrgd6m+/dJa2kVGi6RJYJgEYPBdZ84BZp9dUjNWkBaA==} peerDependencies: "@babel/core": ^7.0.0 dependencies: - "@babel/compat-data": 7.14.0 + "@babel/compat-data": 7.14.4 "@babel/core": 7.14.3 "@babel/helper-validator-option": 7.12.17 browserslist: 4.16.6 semver: 6.3.0 dev: true - /@babel/helper-create-class-features-plugin/7.14.3_@babel+core@7.14.3: - resolution: {integrity: sha512-BnEfi5+6J2Lte9LeiL6TxLWdIlEv9Woacc1qXzXBgbikcOzMRM2Oya5XGg/f/ngotv1ej2A/b+3iJH8wbS1+lQ==} + /@babel/helper-create-class-features-plugin/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-idr3pthFlDCpV+p/rMgGLGYIVtazeatrSOQk8YzO2pAepIjQhCN3myeihVg58ax2bbbGK9PUE1reFi7axOYIOw==} peerDependencies: "@babel/core": ^7.0.0 dependencies: @@ -185,7 +187,7 @@ packages: "@babel/helper-function-name": 7.14.2 "@babel/helper-member-expression-to-functions": 7.13.12 "@babel/helper-optimise-call-expression": 7.12.13 - "@babel/helper-replace-supers": 7.14.3 + "@babel/helper-replace-supers": 7.14.4 "@babel/helper-split-export-declaration": 7.12.13 transitivePeerDependencies: - supports-color @@ -207,7 +209,7 @@ packages: "@babel/core": ^7.4.0-0 dependencies: "@babel/core": 7.14.3 - "@babel/helper-compilation-targets": 7.13.16_@babel+core@7.14.3 + "@babel/helper-compilation-targets": 7.14.4_@babel+core@7.14.3 "@babel/helper-module-imports": 7.13.12 "@babel/helper-plugin-utils": 7.13.0 "@babel/traverse": 7.14.2 @@ -222,7 +224,7 @@ packages: /@babel/helper-explode-assignable-expression/7.13.0: resolution: {integrity: sha512-qS0peLTDP8kOisG1blKbaoBg/o9OSa1qoumMjTK5pM+KDTtpxpsiubnCGP34vK8BXGcb2M9eigwgvoJryrzwWA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-function-name/7.14.2: @@ -230,20 +232,20 @@ packages: dependencies: "@babel/helper-get-function-arity": 7.12.13 "@babel/template": 7.12.13 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-get-function-arity/7.12.13: resolution: {integrity: sha512-DjEVzQNz5LICkzN0REdpD5prGoidvbdYk1BVgRUOINaWJP2t6avB27X1guXK1kXNrX0WMfsrm1A/ZBthYuIMQg==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-hoist-variables/7.13.16: resolution: {integrity: sha512-1eMtTrXtrwscjcAeO4BVK+vvkxaLJSPFz1w1KLawz6HLNi9bPFGBNwwDyVfiu1Tv/vRRFYfoGaKhmAQPGPn5Wg==} dependencies: "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -251,26 +253,26 @@ packages: /@babel/helper-member-expression-to-functions/7.13.12: resolution: {integrity: sha512-48ql1CLL59aKbU94Y88Xgb2VFy7a95ykGRbJJaaVv+LX5U8wFpLfiGXJJGUozsmA1oEh/o5Bp60Voq7ACyA/Sw==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-module-imports/7.13.12: resolution: {integrity: sha512-4cVvR2/1B693IuOvSI20xqqa/+bl7lqAMR59R4iu39R9aOX8/JoYY1sFaNvUMyMBGnHdwvJgUrzNLoUZxXypxA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-module-transforms/7.14.2: resolution: {integrity: sha512-OznJUda/soKXv0XhpvzGWDnml4Qnwp16GN+D/kZIdLsWoHj05kyu8Rm5kXmMef+rVJZ0+4pSGLkeixdqNUATDA==} dependencies: "@babel/helper-module-imports": 7.13.12 - "@babel/helper-replace-supers": 7.14.3 + "@babel/helper-replace-supers": 7.14.4 "@babel/helper-simple-access": 7.13.12 "@babel/helper-split-export-declaration": 7.12.13 "@babel/helper-validator-identifier": 7.14.0 "@babel/template": 7.12.13 "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -278,7 +280,7 @@ packages: /@babel/helper-optimise-call-expression/7.12.13: resolution: {integrity: sha512-BdWQhoVJkp6nVjB7nkFWcn43dkprYauqtk++Py2eaf/GRDFm5BxRqEIZCiHlZUGAVmtwKcsVL1dC68WmzeFmiA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-plugin-utils/7.13.0: @@ -290,18 +292,18 @@ packages: dependencies: "@babel/helper-annotate-as-pure": 7.12.13 "@babel/helper-wrap-function": 7.13.0 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true - /@babel/helper-replace-supers/7.14.3: - resolution: {integrity: sha512-Rlh8qEWZSTfdz+tgNV/N4gz1a0TMNwCUcENhMjHTHKp3LseYH5Jha0NSlyTQWMnjbYcwFt+bqAMqSLHVXkQ6UA==} + /@babel/helper-replace-supers/7.14.4: + resolution: {integrity: sha512-zZ7uHCWlxfEAAOVDYQpEf/uyi1dmeC7fX4nCf2iz9drnCwi1zvwXL3HwWWNXUQEJ1k23yVn3VbddiI9iJEXaTQ==} dependencies: "@babel/helper-member-expression-to-functions": 7.13.12 "@babel/helper-optimise-call-expression": 7.12.13 "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -309,19 +311,19 @@ packages: /@babel/helper-simple-access/7.13.12: resolution: {integrity: sha512-7FEjbrx5SL9cWvXioDbnlYTppcZGuCY6ow3/D5vMggb2Ywgu4dMrpTJX0JdQAIcRRUElOIxF3yEooa9gUb9ZbA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-skip-transparent-expression-wrappers/7.12.1: resolution: {integrity: sha512-Mf5AUuhG1/OCChOJ/HcADmvcHM42WJockombn8ATJG3OnyiSxBK/Mm5x78BQWvmtXZKHgbjdGL2kin/HOLlZGA==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-split-export-declaration/7.12.13: resolution: {integrity: sha512-tCJDltF83htUtXx5NLcaDqRmknv652ZWCHyoTETf1CXYJdPC7nohZohjUgieXhv0hTJdRf2FjDueFehdNucpzg==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@babel/helper-validator-identifier/7.14.0: @@ -338,7 +340,7 @@ packages: "@babel/helper-function-name": 7.14.2 "@babel/template": 7.12.13 "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -348,7 +350,7 @@ packages: dependencies: "@babel/template": 7.12.13 "@babel/traverse": 7.14.2 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -361,8 +363,8 @@ packages: js-tokens: 4.0.0 dev: true - /@babel/parser/7.14.3: - resolution: {integrity: sha512-7MpZDIfI7sUC5zWo2+foJ50CSI5lcqDehZ0lVgIhSi4bFEk94fLAKlF3Q0nzSQQ+ca0lm+O6G9ztKVBeu8PMRQ==} + /@babel/parser/7.14.4: + resolution: {integrity: sha512-ArliyUsWDUqEGfWcmzpGUzNfLxTdTp6WU4IuP6QFSp9gGfWS6boxFCkJSJ/L4+RG8z/FnIU3WxCk6hPL9SSWeA==} engines: {node: ">=6.0.0"} hasBin: true dev: true @@ -397,7 +399,7 @@ packages: "@babel/core": ^7.0.0-0 dependencies: "@babel/core": 7.14.3 - "@babel/helper-create-class-features-plugin": 7.14.3_@babel+core@7.14.3 + "@babel/helper-create-class-features-plugin": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 transitivePeerDependencies: - supports-color @@ -409,7 +411,7 @@ packages: "@babel/core": ^7.12.0 dependencies: "@babel/core": 7.14.3 - "@babel/helper-create-class-features-plugin": 7.14.3_@babel+core@7.14.3 + "@babel/helper-create-class-features-plugin": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 "@babel/plugin-syntax-class-static-block": 7.12.13_@babel+core@7.14.3 transitivePeerDependencies: @@ -476,14 +478,14 @@ packages: "@babel/plugin-syntax-numeric-separator": 7.10.4_@babel+core@7.14.3 dev: true - /@babel/plugin-proposal-object-rest-spread/7.14.2_@babel+core@7.14.3: - resolution: {integrity: sha512-hBIQFxwZi8GIp934+nj5uV31mqclC1aYDhctDu5khTi9PCCUOczyy0b34W0oE9U/eJXiqQaKyVsmjeagOaSlbw==} + /@babel/plugin-proposal-object-rest-spread/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-AYosOWBlyyXEagrPRfLJ1enStufsr7D1+ddpj8OLi9k7B6+NdZ0t/9V7Fh+wJ4g2Jol8z2JkgczYqtWrZd4vbA==} peerDependencies: "@babel/core": ^7.0.0-0 dependencies: - "@babel/compat-data": 7.14.0 + "@babel/compat-data": 7.14.4 "@babel/core": 7.14.3 - "@babel/helper-compilation-targets": 7.13.16_@babel+core@7.14.3 + "@babel/helper-compilation-targets": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 "@babel/plugin-syntax-object-rest-spread": 7.8.3_@babel+core@7.14.3 "@babel/plugin-transform-parameters": 7.14.2_@babel+core@7.14.3 @@ -516,7 +518,7 @@ packages: "@babel/core": ^7.0.0-0 dependencies: "@babel/core": 7.14.3 - "@babel/helper-create-class-features-plugin": 7.14.3_@babel+core@7.14.3 + "@babel/helper-create-class-features-plugin": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 transitivePeerDependencies: - supports-color @@ -529,7 +531,7 @@ packages: dependencies: "@babel/core": 7.14.3 "@babel/helper-annotate-as-pure": 7.12.13 - "@babel/helper-create-class-features-plugin": 7.14.3_@babel+core@7.14.3 + "@babel/helper-create-class-features-plugin": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 "@babel/plugin-syntax-private-property-in-object": 7.14.0_@babel+core@7.14.3 transitivePeerDependencies: @@ -704,8 +706,8 @@ packages: "@babel/helper-plugin-utils": 7.13.0 dev: true - /@babel/plugin-transform-block-scoping/7.14.2_@babel+core@7.14.3: - resolution: {integrity: sha512-neZZcP19NugZZqNwMTH+KoBjx5WyvESPSIOQb4JHpfd+zPfqcH65RMu5xJju5+6q/Y2VzYrleQTr+b6METyyxg==} + /@babel/plugin-transform-block-scoping/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-5KdpkGxsZlTk+fPleDtGKsA+pon28+ptYmMO8GBSa5fHERCJWAzj50uAfCKBqq42HO+Zot6JF1x37CRprwmN4g==} peerDependencies: "@babel/core": ^7.0.0-0 dependencies: @@ -713,8 +715,8 @@ packages: "@babel/helper-plugin-utils": 7.13.0 dev: true - /@babel/plugin-transform-classes/7.14.2_@babel+core@7.14.3: - resolution: {integrity: sha512-7oafAVcucHquA/VZCsXv/gmuiHeYd64UJyyTYU+MPfNu0KeNlxw06IeENBO8bJjXVbolu+j1MM5aKQtH1OMCNg==} + /@babel/plugin-transform-classes/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-p73t31SIj6y94RDVX57rafVjttNr8MvKEgs5YFatNB/xC68zM3pyosuOEcQmYsYlyQaGY9R7rAULVRcat5FKJQ==} peerDependencies: "@babel/core": ^7.0.0-0 dependencies: @@ -723,7 +725,7 @@ packages: "@babel/helper-function-name": 7.14.2 "@babel/helper-optimise-call-expression": 7.12.13 "@babel/helper-plugin-utils": 7.13.0 - "@babel/helper-replace-supers": 7.14.3 + "@babel/helper-replace-supers": 7.14.4 "@babel/helper-split-export-declaration": 7.12.13 globals: 11.12.0 transitivePeerDependencies: @@ -739,8 +741,8 @@ packages: "@babel/helper-plugin-utils": 7.13.0 dev: true - /@babel/plugin-transform-destructuring/7.13.17_@babel+core@7.14.3: - resolution: {integrity: sha512-UAUqiLv+uRLO+xuBKKMEpC+t7YRNVRqBsWWq1yKXbBZBje/t3IXCiSinZhjn/DC3qzBfICeYd2EFGEbHsh5RLA==} + /@babel/plugin-transform-destructuring/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-JyywKreTCGTUsL1OKu1A3ms/R1sTP0WxbpXlALeGzF53eB3bxtNkYdMj9SDgK7g6ImPy76J5oYYKoTtQImlhQA==} peerDependencies: "@babel/core": ^7.0.0-0 dependencies: @@ -893,7 +895,7 @@ packages: dependencies: "@babel/core": 7.14.3 "@babel/helper-plugin-utils": 7.13.0 - "@babel/helper-replace-supers": 7.14.3 + "@babel/helper-replace-supers": 7.14.4 transitivePeerDependencies: - supports-color dev: true @@ -1015,14 +1017,14 @@ packages: "@babel/helper-plugin-utils": 7.13.0 dev: true - /@babel/preset-env/7.14.2_@babel+core@7.14.3: - resolution: {integrity: sha512-7dD7lVT8GMrE73v4lvDEb85cgcQhdES91BSD7jS/xjC6QY8PnRhux35ac+GCpbiRhp8crexBvZZqnaL6VrY8TQ==} + /@babel/preset-env/7.14.4_@babel+core@7.14.3: + resolution: {integrity: sha512-GwMMsuAnDtULyOtuxHhzzuSRxFeP0aR/LNzrHRzP8y6AgDNgqnrfCCBm/1cRdTU75tRs28Eh76poHLcg9VF0LA==} peerDependencies: "@babel/core": ^7.0.0-0 dependencies: - "@babel/compat-data": 7.14.0 + "@babel/compat-data": 7.14.4 "@babel/core": 7.14.3 - "@babel/helper-compilation-targets": 7.13.16_@babel+core@7.14.3 + "@babel/helper-compilation-targets": 7.14.4_@babel+core@7.14.3 "@babel/helper-plugin-utils": 7.13.0 "@babel/helper-validator-option": 7.12.17 "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": 7.13.12_@babel+core@7.14.3 @@ -1035,7 +1037,7 @@ packages: "@babel/plugin-proposal-logical-assignment-operators": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-nullish-coalescing-operator": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-numeric-separator": 7.14.2_@babel+core@7.14.3 - "@babel/plugin-proposal-object-rest-spread": 7.14.2_@babel+core@7.14.3 + "@babel/plugin-proposal-object-rest-spread": 7.14.4_@babel+core@7.14.3 "@babel/plugin-proposal-optional-catch-binding": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-optional-chaining": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-private-methods": 7.13.0_@babel+core@7.14.3 @@ -1058,10 +1060,10 @@ packages: "@babel/plugin-transform-arrow-functions": 7.13.0_@babel+core@7.14.3 "@babel/plugin-transform-async-to-generator": 7.13.0_@babel+core@7.14.3 "@babel/plugin-transform-block-scoped-functions": 7.12.13_@babel+core@7.14.3 - "@babel/plugin-transform-block-scoping": 7.14.2_@babel+core@7.14.3 - "@babel/plugin-transform-classes": 7.14.2_@babel+core@7.14.3 + "@babel/plugin-transform-block-scoping": 7.14.4_@babel+core@7.14.3 + "@babel/plugin-transform-classes": 7.14.4_@babel+core@7.14.3 "@babel/plugin-transform-computed-properties": 7.13.0_@babel+core@7.14.3 - "@babel/plugin-transform-destructuring": 7.13.17_@babel+core@7.14.3 + "@babel/plugin-transform-destructuring": 7.14.4_@babel+core@7.14.3 "@babel/plugin-transform-dotall-regex": 7.12.13_@babel+core@7.14.3 "@babel/plugin-transform-duplicate-keys": 7.12.13_@babel+core@7.14.3 "@babel/plugin-transform-exponentiation-operator": 7.12.13_@babel+core@7.14.3 @@ -1088,7 +1090,7 @@ packages: "@babel/plugin-transform-unicode-escapes": 7.12.13_@babel+core@7.14.3 "@babel/plugin-transform-unicode-regex": 7.12.13_@babel+core@7.14.3 "@babel/preset-modules": 0.1.4_@babel+core@7.14.3 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 babel-plugin-polyfill-corejs2: 0.2.2_@babel+core@7.14.3 babel-plugin-polyfill-corejs3: 0.2.2_@babel+core@7.14.3 babel-plugin-polyfill-regenerator: 0.2.2_@babel+core@7.14.3 @@ -1107,7 +1109,7 @@ packages: "@babel/helper-plugin-utils": 7.13.0 "@babel/plugin-proposal-unicode-property-regex": 7.12.13_@babel+core@7.14.3 "@babel/plugin-transform-dotall-regex": 7.12.13_@babel+core@7.14.3 - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 esutils: 2.0.3 dev: true @@ -1121,8 +1123,8 @@ packages: resolution: {integrity: sha512-/7xxiGA57xMo/P2GVvdEumr8ONhFOhfgq2ihK3h1e6THqzTAkHbkXgB0xI9yeTfIUoH3+oAeHhqm/I43OTbbjA==} dependencies: "@babel/code-frame": 7.12.13 - "@babel/parser": 7.14.3 - "@babel/types": 7.14.2 + "@babel/parser": 7.14.4 + "@babel/types": 7.14.4 dev: true /@babel/traverse/7.14.2: @@ -1132,16 +1134,16 @@ packages: "@babel/generator": 7.14.3 "@babel/helper-function-name": 7.14.2 "@babel/helper-split-export-declaration": 7.12.13 - "@babel/parser": 7.14.3 - "@babel/types": 7.14.2 + "@babel/parser": 7.14.4 + "@babel/types": 7.14.4 debug: 4.3.1 globals: 11.12.0 transitivePeerDependencies: - supports-color dev: true - /@babel/types/7.14.2: - resolution: {integrity: sha512-SdjAG/3DikRHpUOjxZgnkbR11xUlyDMUFJdvnIgZEE16mqmY0BINMmc4//JMJglEmn6i7sq6p+mGrFWyZ98EEw==} + /@babel/types/7.14.4: + resolution: {integrity: sha512-lCj4aIs0xUefJFQnwwQv2Bxg7Omd6bgquZ6LGC+gGMh6/s5qDVfjuCMlDmYQ15SLsWHd9n+X3E75lKIhl5Lkiw==} dependencies: "@babel/helper-validator-identifier": 7.14.0 to-fast-properties: 2.0.0 @@ -1180,8 +1182,8 @@ packages: - supports-color dev: true - /@mdn/browser-compat-data/3.3.4: - resolution: {integrity: sha512-J8vDIdqtOv0O9IzZrOJgUPHlncNePoLfr0/Hsb4x5IMFtn1xlLbaOfD+moFYhHGhXBd/6FfTKgD+DvDSI3zhYA==} + /@mdn/browser-compat-data/3.3.5: + resolution: {integrity: sha512-Pu2Usbl9YTpeNxYKRebFRE4fV85I/thTMpF1eKS2EsgODg9VkcK0/oRZqEFhR6/So5wSPYIBHvfmVFXx0uCt/g==} dev: true /@nodelib/fs.scandir/2.1.4: @@ -1252,22 +1254,22 @@ packages: read-package-json-fast: 2.0.2 dev: true - /@rollup/plugin-node-resolve/13.0.0_rollup@2.50.1: + /@rollup/plugin-node-resolve/13.0.0_rollup@2.50.3: resolution: {integrity: sha512-41X411HJ3oikIDivT5OKe9EZ6ud6DXudtfNrGbC4nniaxx2esiWjkLOzgnZsWq1IM8YIeL2rzRGLZLBjlhnZtQ==} engines: {node: ">= 10.0.0"} peerDependencies: rollup: ^2.42.0 dependencies: - "@rollup/pluginutils": 3.1.0_rollup@2.50.1 + "@rollup/pluginutils": 3.1.0_rollup@2.50.3 "@types/resolve": 1.17.1 builtin-modules: 3.2.0 deepmerge: 4.2.2 is-module: 1.0.0 resolve: 1.20.0 - rollup: 2.50.1 + rollup: 2.50.3 dev: true - /@rollup/pluginutils/3.1.0_rollup@2.50.1: + /@rollup/pluginutils/3.1.0_rollup@2.50.3: resolution: {integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==} engines: {node: ">= 8.0.0"} peerDependencies: @@ -1276,10 +1278,10 @@ packages: "@types/estree": 0.0.39 estree-walker: 1.0.1 picomatch: 2.3.0 - rollup: 2.50.1 + rollup: 2.50.3 dev: true - /@rollup/pluginutils/4.1.0_rollup@2.50.1: + /@rollup/pluginutils/4.1.0_rollup@2.50.3: resolution: {integrity: sha512-TrBhfJkFxA+ER+ew2U2/fHbebhLT/l/2pRk0hfj9KusXUuRXd2v0R58AfaZK9VXDQ4TogOSEmICVrQAA3zFnHQ==} engines: {node: ">= 8.0.0"} peerDependencies: @@ -1287,7 +1289,7 @@ packages: dependencies: estree-walker: 2.0.2 picomatch: 2.3.0 - rollup: 2.50.1 + rollup: 2.50.3 dev: true /@samverschueren/stream-to-observable/0.3.1_rxjs@6.6.7: @@ -1359,8 +1361,8 @@ packages: /@types/babel__core/7.1.14: resolution: {integrity: sha512-zGZJzzBUVDo/eV6KgbE0f0ZI7dInEYvo12Rb70uNQDshC3SkRMb67ja0GgRHZgAX3Za6rhaWlvbDO8rrGyAb1g==} dependencies: - "@babel/parser": 7.14.3 - "@babel/types": 7.14.2 + "@babel/parser": 7.14.4 + "@babel/types": 7.14.4 "@types/babel__generator": 7.6.2 "@types/babel__template": 7.4.0 "@types/babel__traverse": 7.11.1 @@ -1369,20 +1371,20 @@ packages: /@types/babel__generator/7.6.2: resolution: {integrity: sha512-MdSJnBjl+bdwkLskZ3NGFp9YcXGx5ggLpQQPqtgakVhsWK0hTtNYhjpZLlWQTviGTvF8at+Bvli3jV7faPdgeQ==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@types/babel__template/7.4.0: resolution: {integrity: sha512-NTPErx4/FiPCGScH7foPyr+/1Dkzkni+rHiYHHoTjvwou7AQzJkNeD60A9CXRy+ZEN2B1bggmkTMCDb+Mv5k+A==} dependencies: - "@babel/parser": 7.14.3 - "@babel/types": 7.14.2 + "@babel/parser": 7.14.4 + "@babel/types": 7.14.4 dev: true /@types/babel__traverse/7.11.1: resolution: {integrity: sha512-Vs0hm0vPahPMYi9tDjtP66llufgO3ST16WXaSTtDGEl9cewAl3AibmxWw6TINOqHPT9z0uABKAYjT9jNSg4npw==} dependencies: - "@babel/types": 7.14.2 + "@babel/types": 7.14.4 dev: true /@types/cacheable-request/6.0.1: @@ -1582,7 +1584,7 @@ packages: engines: {node: ">=8.0.0"} deprecated: wessberg/browserslist-generator has been renamed to browserslist-generator. Please use browserslist-generator instead dependencies: - "@mdn/browser-compat-data": 3.3.4 + "@mdn/browser-compat-data": 3.3.5 "@types/object-path": 0.11.0 "@types/semver": 7.3.6 "@types/ua-parser-js": 0.7.36 @@ -1593,7 +1595,7 @@ packages: ua-parser-js: 0.7.28 dev: true - /@wessberg/rollup-plugin-ts/1.3.14_rollup@2.50.1+typescript@4.3.2: + /@wessberg/rollup-plugin-ts/1.3.14_rollup@2.50.3+typescript@4.3.2: resolution: {integrity: sha512-k1a//kf27mGpDgX/duQ4TUOqUJ0d20tOoCS2mkS5TF5vu3ZC6xNaDXkrL/ZBOqP840GW12L1UqyHQmc3D9ULng==} engines: {node: ">=10.0.0"} peerDependencies: @@ -1603,14 +1605,14 @@ packages: "@babel/core": 7.14.3 "@babel/plugin-proposal-async-generator-functions": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-json-strings": 7.14.2_@babel+core@7.14.3 - "@babel/plugin-proposal-object-rest-spread": 7.14.2_@babel+core@7.14.3 + "@babel/plugin-proposal-object-rest-spread": 7.14.4_@babel+core@7.14.3 "@babel/plugin-proposal-optional-catch-binding": 7.14.2_@babel+core@7.14.3 "@babel/plugin-proposal-unicode-property-regex": 7.12.13_@babel+core@7.14.3 "@babel/plugin-syntax-dynamic-import": 7.8.3_@babel+core@7.14.3 "@babel/plugin-transform-runtime": 7.14.3_@babel+core@7.14.3 - "@babel/preset-env": 7.14.2_@babel+core@7.14.3 + "@babel/preset-env": 7.14.4_@babel+core@7.14.3 "@babel/runtime": 7.14.0 - "@rollup/pluginutils": 4.1.0_rollup@2.50.1 + "@rollup/pluginutils": 4.1.0_rollup@2.50.3 "@types/babel__core": 7.1.14 "@wessberg/browserslist-generator": 1.0.47 "@wessberg/stringutil": 1.0.19 @@ -1618,7 +1620,7 @@ packages: browserslist: 4.16.6 chalk: 4.1.1 magic-string: 0.25.7 - rollup: 2.50.1 + rollup: 2.50.3 slash: 3.0.0 tslib: 2.2.0 typescript: 4.3.2 @@ -1639,8 +1641,8 @@ packages: typescript: 4.3.2 dev: true - /@wessberg/ts-config/1.1.0: - resolution: {integrity: sha512-bRW9BTM6C7CkMP3PhcYeUsSy2l7hBpPm3O/cbs6V+4bYeL473BxA+0ix6auahL3XoeBIEWCr/FKzZsrVCzRlZw==} + /@wessberg/ts-config/1.1.2: + resolution: {integrity: sha512-ypOs3NErwEgAmmJ1Il7/zx0V0s9UQJEycHWd204KYxnrI+C3vBDm8iLCRKQA9F9mxJJUkiiL/r5wnX0I8OaDOw==} dev: true /JSONStream/1.3.5: @@ -1881,7 +1883,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.3 - es-abstract: 1.18.2 + es-abstract: 1.18.3 get-intrinsic: 1.1.1 is-string: 1.0.6 dev: true @@ -1897,7 +1899,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.3 - es-abstract: 1.18.2 + es-abstract: 1.18.3 dev: true /arrgv/1.0.2: @@ -2030,7 +2032,7 @@ packages: peerDependencies: "@babel/core": ^7.0.0-0 dependencies: - "@babel/compat-data": 7.14.0 + "@babel/compat-data": 7.14.4 "@babel/core": 7.14.3 "@babel/helper-define-polyfill-provider": 0.2.3_@babel+core@7.14.3 semver: 6.3.0 @@ -2126,7 +2128,7 @@ packages: dependencies: caniuse-lite: 1.0.30001230 colorette: 1.2.2 - electron-to-chromium: 1.3.739 + electron-to-chromium: 1.3.741 escalade: 3.1.1 node-releases: 1.1.72 dev: true @@ -2138,7 +2140,7 @@ packages: dependencies: caniuse-lite: 1.0.30001230 colorette: 1.2.2 - electron-to-chromium: 1.3.739 + electron-to-chromium: 1.3.741 escalade: 3.1.1 node-releases: 1.1.72 dev: true @@ -2511,6 +2513,16 @@ packages: dot-prop: 5.3.0 dev: true + /compatfactory/0.0.1_typescript@4.3.2: + resolution: {integrity: sha512-oMxhv1rG9A7OYCyvfk2e1nCXmbjcfdECTWBhkbsdZDLG6a9c2OnlbcvuXKNvQuH6YOqIRAPHT6Vs66IibN7xTw==} + engines: {node: ">=10.0.0"} + peerDependencies: + typescript: ">=3.x || >= 4.x" + dependencies: + helpertypes: 0.0.2 + typescript: 4.3.2 + dev: false + /concat-map/0.0.1: resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} dev: true @@ -2892,8 +2904,8 @@ packages: safer-buffer: 2.1.2 dev: true - /electron-to-chromium/1.3.739: - resolution: {integrity: sha512-+LPJVRsN7hGZ9EIUUiWCpO7l4E3qBYHNadazlucBfsXBbccDFNKUBAgzE68FnkWGJPwD/AfKhSzL+G+Iqb8A4A==} + /electron-to-chromium/1.3.741: + resolution: {integrity: sha512-4i3T0cwnHo1O4Mnp9JniEco8bZiXoqbm3PhW5hv7uu8YLg35iajYrRnNyKFaN8/8SSTskU2hYqVTeYVPceSpUA==} dev: true /elegant-spinner/1.0.1: @@ -2954,8 +2966,8 @@ packages: is-arrayish: 0.2.1 dev: true - /es-abstract/1.18.2: - resolution: {integrity: sha512-byRiNIQXE6HWNySaU6JohoNXzYgbBjztwFnBLUTiJmWXjaU9bSq3urQLUlNLQ292tc+gc07zYZXNZjaOoAX3sw==} + /es-abstract/1.18.3: + resolution: {integrity: sha512-nQIr12dxV7SSxE6r6f1l3DtAeEYdsGpps13dR0TwJg1S8gyp4ZPgy3FZcHBgbiQqnoqSTb+oC+kO4UQ0C/J8vw==} engines: {node: ">= 0.4"} dependencies: call-bind: 1.0.2 @@ -3132,7 +3144,7 @@ packages: file-entry-cache: 6.0.1 functional-red-black-tree: 1.0.1 glob-parent: 5.1.2 - globals: 13.8.0 + globals: 13.9.0 ignore: 4.0.6 import-fresh: 3.3.0 imurmurhash: 0.1.4 @@ -3620,8 +3632,8 @@ packages: type-fest: 0.8.1 dev: true - /globals/13.8.0: - resolution: {integrity: sha512-rHtdA6+PDBIjeEvA91rpqzEvk/k3/i7EeNQiryiWuJH0Hw9cpyJMAt2jtbAwUaRdhD+573X4vWw6IcjKPasi9Q==} + /globals/13.9.0: + resolution: {integrity: sha512-74/FduwI/JaIrr1H8e71UbDE+5x7pIPs1C2rrwC52SszOo043CsWOZEMW7o2Y58xwm9b+0RBKDxY5n2sUpEFxA==} engines: {node: ">=8"} dependencies: type-fest: 0.20.2 @@ -3773,8 +3785,8 @@ packages: dependencies: function-bind: 1.1.1 - /helpertypes/0.0.1: - resolution: {integrity: sha512-aNME00V4Q1qn1cWG+cM65W6C+sZoUvk+qR1sfGkYRDvDDqfT9xD6/+I1dry3h4mq76BQTl/8oWq/mY/jueOhbg==} + /helpertypes/0.0.2: + resolution: {integrity: sha512-PKVtWnJ+dcvPeUJRiqtbraN/Hr2rNEnS14T/IxDBb0KgHkAL5w4YwVxMEPowA9vyoMP0DrwO0TxJ+KH3UF/6YA==} engines: {node: ">=10.0.0"} /hosted-git-info/2.8.9: @@ -4920,7 +4932,7 @@ packages: normalize-package-data: 3.0.2 read-pkg-up: 7.0.1 redent: 3.0.0 - trim-newlines: 3.0.0 + trim-newlines: 3.0.1 type-fest: 0.18.1 yargs-parser: 20.2.7 dev: true @@ -5422,7 +5434,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.3 - es-abstract: 1.18.2 + es-abstract: 1.18.3 dev: true /once/1.4.0: @@ -5841,8 +5853,8 @@ packages: irregular-plurals: 3.3.0 dev: true - /pnpm/6.4.0: - resolution: {integrity: sha512-ws4OArFXDfjOrj6gk4Ded+CkbW6pRKkscnOEONetX2MV+m5fwxTIAVw2Fic4CNTKZbN4D182oPQyoMd5uGzrjw==} + /pnpm/6.6.1: + resolution: {integrity: sha512-viktTHmFzFckpvY/Gwtl8esjeOItpCgycIrVgLPh4qbxK4f+JqkEM+3LZF5dudyWzBZCOspZHePNuxeM0zn/Ew==} engines: {node: ">=12.17"} hasBin: true dev: true @@ -6305,8 +6317,8 @@ packages: glob: 7.1.7 dev: true - /rollup/2.50.1: - resolution: {integrity: sha512-3MQhSdGpms4xjYrtR3WNHMT+VrWWM4oqUxUC770MmLo1FWFR2pr/OL81HSPC/ifmiu0uMFk0qPGLmjkSMRIESw==} + /rollup/2.50.3: + resolution: {integrity: sha512-58KiHnaCzZn6F5yRMjHe7WTZuFj6r4iJVJz5UwvKD6f/xfTy2IdtbR2AVHN6cyfK1tBy//hJ66ebXy6Y1h7HlQ==} engines: {node: ">=10.0.0"} hasBin: true optionalDependencies: @@ -6342,8 +6354,8 @@ packages: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: true - /sandhog/1.0.40: - resolution: {integrity: sha512-uWZFAOoyloa6TsJxPY0Sb40sRi6k3M7/FRB71EpsQ9EGYY7nLlQDRJata7YrFOfe2LNxxCiQT3WKba2uLW4Idw==} + /sandhog/1.0.41: + resolution: {integrity: sha512-BbXm27YfmT42RQVktXaLwMIo35zC73KYBmqkiT2BeY5Rhb65w7j4MViVVm+EAZRRc+5rOFVlp729Gdhv/aGpPA==} engines: {node: ">=10.0.0"} hasBin: true dependencies: @@ -6351,7 +6363,7 @@ packages: chalk: 4.1.1 commander: 7.2.0 eslint: 7.27.0 - helpertypes: 0.0.1 + helpertypes: 0.0.2 inquirer: 8.1.0 json5: 2.2.0 markdown-toc: 1.2.0 @@ -6927,8 +6939,8 @@ packages: engines: {node: ">=0.10.0"} dev: true - /trim-newlines/3.0.0: - resolution: {integrity: sha512-C4+gOpvmxaSMKuEf9Qc134F1ZuOHVXKRbtEflf4NTtuuJDEIJ9p5PXsalL8SkeRw+qit1Mo+yuvMPAKwWg/1hA==} + /trim-newlines/3.0.1: + resolution: {integrity: sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==} engines: {node: ">=8"} dev: true @@ -7226,6 +7238,7 @@ packages: /uuid/3.4.0: resolution: {integrity: sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==} + deprecated: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. hasBin: true dev: true diff --git a/sandhog.config.js b/sandhog.config.js index 99cb270..aba65c4 100644 --- a/sandhog.config.js +++ b/sandhog.config.js @@ -1,5 +1,11 @@ -module.exports = { - ...require("@wessberg/ts-config/sandhog.config"), +/* eslint-disable @typescript-eslint/no-require-imports */ +// @ts-check + +/** + * @type {import("helpertypes").PartialDeep} + */ +const config = { + ...require("@wessberg/ts-config/sandhog.config.json"), logo: { url: "https://raw.githubusercontent.com/wessberg/cjstoesm/master/documentation/asset/logo.png", height: 150 @@ -9,3 +15,5 @@ module.exports = { url: "https://raw.githubusercontent.com/wessberg/cjstoesm/master/documentation/asset/feature.gif" } }; + +module.exports = config; diff --git a/src/index.ts b/src/index.ts index cc04a21..80d4245 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ export * from "./transformer/cjs-to-esm"; export * from "./transformer/cjs-to-esm-options"; -export * from "./transformer/cjs-to-esm-transformer-factory"; +export * from "./transformer/cjs-to-esm-transformer"; export * from "./api/transform"; export * from "./shared/task/transform-task-options"; export * from "./shared/task/transform-result"; diff --git a/src/transformer/before/before-transformer-options.ts b/src/transformer/before/before-transformer-options.ts deleted file mode 100644 index bfb0754..0000000 --- a/src/transformer/before/before-transformer-options.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {VisitorContext} from "../visitor-context"; - -export interface BeforeTransformerOptions { - baseVisitorContext: VisitorContext; -} diff --git a/src/transformer/before/before-transformer.ts b/src/transformer/before/before-transformer.ts deleted file mode 100644 index a7014f1..0000000 --- a/src/transformer/before/before-transformer.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {BeforeTransformerOptions} from "./before-transformer-options"; -import {transformSourceFile} from "./transform-source-file"; -import {TS} from "../../type/ts"; - -/** - * @param options - * @return - */ -export function beforeTransformer(options: BeforeTransformerOptions): TS.TransformerFactory { - return context => sourceFile => transformSourceFile(sourceFile, options, context).sourceFile; -} diff --git a/src/transformer/cjs-to-esm-transformer-factory.ts b/src/transformer/cjs-to-esm-transformer-factory.ts deleted file mode 100644 index 5c55cc7..0000000 --- a/src/transformer/cjs-to-esm-transformer-factory.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {beforeTransformer} from "./before/before-transformer"; -import {VisitorContext} from "./visitor-context"; -import {TS} from "../type/ts"; -import {createSafeFileSystem} from "../shared/file-system/file-system"; -import {CjsToEsmOptions} from "./cjs-to-esm-options"; -import {createTaskOptions} from "../shared/task/create-task-options"; - -/** - * A TransformerFactory that converts CommonJS to tree-shakeable ESM - */ -export function cjsToEsmTransformerFactory(options: Partial = {}): TS.TransformerFactory { - const sanitizedOptions = createTaskOptions(options); - const {fileSystem, typescript} = sanitizedOptions; - - // Prepare a VisitorContext - const visitorContext = ((): VisitorContext => ({ - ...sanitizedOptions, - fileSystem: createSafeFileSystem(fileSystem), - onlyExports: false, - resolveCache: new Map(), - printer: typescript.createPrinter() - }))(); - - return beforeTransformer({baseVisitorContext: visitorContext}); -} diff --git a/src/transformer/cjs-to-esm-transformer.ts b/src/transformer/cjs-to-esm-transformer.ts new file mode 100644 index 0000000..cb4abcf --- /dev/null +++ b/src/transformer/cjs-to-esm-transformer.ts @@ -0,0 +1,27 @@ +import {transformSourceFile} from "./transform-source-file"; +import {TS} from "../type/ts"; +import {createTaskOptions} from "../shared/task/create-task-options"; +import {createSafeFileSystem} from "../shared/file-system/file-system"; +import {VisitorContext} from "./visitor-context"; +import {ensureNodeFactory} from "compatfactory"; +import {CjsToEsmOptions} from "./cjs-to-esm-options"; + +export function cjsToEsmTransformer(options: Partial = {}): TS.TransformerFactory { + return context => { + const sanitizedOptions = createTaskOptions(options); + const {fileSystem, typescript} = sanitizedOptions; + + // Prepare a VisitorContext + const visitorContext: VisitorContext = { + ...sanitizedOptions, + transformationContext: context, + factory: ensureNodeFactory(context.factory ?? typescript), + fileSystem: createSafeFileSystem(fileSystem), + onlyExports: false, + resolveCache: new Map(), + printer: typescript.createPrinter() + }; + + return sourceFile => transformSourceFile(sourceFile, visitorContext).sourceFile; + }; +} diff --git a/src/transformer/cjs-to-esm.ts b/src/transformer/cjs-to-esm.ts index 6619178..398152b 100644 --- a/src/transformer/cjs-to-esm.ts +++ b/src/transformer/cjs-to-esm.ts @@ -1,12 +1,12 @@ -import {cjsToEsmTransformerFactory} from "./cjs-to-esm-transformer-factory"; import {TS} from "../type/ts"; import {CjsToEsmOptions} from "./cjs-to-esm-options"; +import {cjsToEsmTransformer} from "./cjs-to-esm-transformer"; /** * CustomTransformer that converts CommonJS to tree-shakeable ESM */ export function cjsToEsm(options?: Partial): TS.CustomTransformers { return { - before: [cjsToEsmTransformerFactory(options)] + before: [cjsToEsmTransformer(options)] }; } diff --git a/src/transformer/before/transform-source-file.ts b/src/transformer/transform-source-file.ts similarity index 90% rename from src/transformer/before/transform-source-file.ts rename to src/transformer/transform-source-file.ts index c019e52..23de3b5 100644 --- a/src/transformer/before/transform-source-file.ts +++ b/src/transformer/transform-source-file.ts @@ -2,34 +2,28 @@ import {visitNode} from "./visitor/visit/visit-node"; import {BeforeVisitorContext} from "./visitor/before-visitor-context"; import {BeforeVisitorOptions} from "./visitor/before-visitor-options"; import {check} from "reserved-words"; -import {isNamedDeclaration} from "../util/is-named-declaration"; -import {BeforeTransformerOptions} from "./before-transformer-options"; -import {getLocalsForBindingName} from "../util/get-locals-for-binding-name"; -import {shouldSkipEmit} from "../util/should-skip-emit"; -import {ModuleExports} from "../module-exports/module-exports"; +import {isNamedDeclaration} from "./util/is-named-declaration"; +import {getLocalsForBindingName} from "./util/get-locals-for-binding-name"; +import {shouldSkipEmit} from "./util/should-skip-emit"; +import {ModuleExports} from "./module-exports/module-exports"; import {visitImportAndExportDeclarations} from "./visitor/visit/visit-import-and-export-declarations"; -import {TS} from "../../type/ts"; -import {shouldDebug} from "../util/should-debug"; -import {isNodeFactory} from "../util/is-node-factory"; +import {TS} from "../type/ts"; +import {shouldDebug} from "./util/should-debug"; import path from "crosspath"; +import {VisitorContext} from "./visitor-context"; export interface BeforeTransformerSourceFileStepResult { sourceFile: TS.SourceFile; exports: ModuleExports; } -export function transformSourceFile( - sourceFile: TS.SourceFile, - {baseVisitorContext}: BeforeTransformerOptions, - context: TS.TransformationContext -): BeforeTransformerSourceFileStepResult { +export function transformSourceFile(sourceFile: TS.SourceFile, context: VisitorContext): BeforeTransformerSourceFileStepResult { // Take a fast path of the text of the SourceFile doesn't contain anything that can be transformed - if (!baseVisitorContext.onlyExports && !sourceFile.text.includes("require") && !sourceFile.text.includes("exports")) { + if (!context.onlyExports && !sourceFile.text.includes("require") && !sourceFile.text.includes("exports")) { return {sourceFile, exports: {namedExports: new Set(), hasDefaultExport: false}}; } - const {typescript} = baseVisitorContext; - const compatFactory = (context.factory as TS.NodeFactory | undefined) ?? typescript; + const {typescript, factory, transformationContext} = context; // Prepare a VisitorContext const visitorContext = ((): BeforeVisitorContext => { @@ -156,8 +150,7 @@ export function transformSourceFile( }; return { - ...baseVisitorContext, - transformationContext: context, + ...context, exportsName: undefined, addImport, addLocal, @@ -198,7 +191,6 @@ export function transformSourceFile( })(); const visitorBaseOptions: Pick, Exclude, "node" | "sourceFile">> = { - compatFactory, context: visitorContext, continuation: node => @@ -217,16 +209,15 @@ export function transformSourceFile( node: cbNode }); if (shouldSkipEmit(visitResult, typescript)) { - return compatFactory.createNotEmittedStatement(cbNode); + return factory.createNotEmittedStatement(cbNode); } return visitResult; }, - context + transformationContext ) }; const importVisitorBaseOptions: Pick, Exclude, "node" | "sourceFile">> = { - compatFactory, context: visitorContext, continuation: node => @@ -245,11 +236,11 @@ export function transformSourceFile( node: cbNode }); if (shouldSkipEmit(visitResult, typescript)) { - return compatFactory.createNotEmittedStatement(cbNode); + return factory.createNotEmittedStatement(cbNode); } return visitResult; }, - context + transformationContext ) }; @@ -279,7 +270,7 @@ export function transformSourceFile( ...visitorContext.trailingStatements.filter(statement => !allImports.includes(statement) && !allExports.includes(statement)) ]; - updatedSourceFile = (isNodeFactory(compatFactory) ? compatFactory.updateSourceFile : compatFactory.updateSourceFileNode)( + updatedSourceFile = factory.updateSourceFile( updatedSourceFile, [...allImports, ...allOtherStatements, ...allExports], sourceFile.isDeclarationFile, diff --git a/src/transformer/util/add-export-modifier.ts b/src/transformer/util/add-export-modifier.ts index 559d405..c418e24 100644 --- a/src/transformer/util/add-export-modifier.ts +++ b/src/transformer/util/add-export-modifier.ts @@ -1,19 +1,16 @@ import {TS} from "../../type/ts"; -import {CompatFactory} from "../../type/compat-factory"; +import {VisitorContext} from "../visitor-context"; -export function addExportModifier( - modifiers: T | undefined, - typescript: typeof TS, - compatFactory: CompatFactory -): T extends TS.ModifiersArray ? TS.ModifiersArray : undefined { +export function addExportModifier(modifiers: T | undefined, context: VisitorContext): T extends TS.ModifiersArray ? TS.ModifiersArray : undefined { + const {factory, typescript} = context; if (modifiers == null) { - modifiers = compatFactory.createNodeArray() as T; + modifiers = factory.createNodeArray() as T; } else if (modifiers.some(m => m.kind === typescript.SyntaxKind.ExportKeyword)) { return modifiers as unknown as T extends TS.ModifiersArray ? TS.ModifiersArray : undefined; } - return compatFactory.createNodeArray([ - compatFactory.createModifier(typescript.SyntaxKind.ExportKeyword), - ...modifiers.map(m => compatFactory.createModifier(m.kind)) + return factory.createNodeArray([ + factory.createModifier(typescript.SyntaxKind.ExportKeyword), + ...modifiers.map(m => factory.createModifier(m.kind)) ]) as T extends TS.ModifiersArray ? TS.ModifiersArray : undefined; } diff --git a/src/transformer/util/ensure-node-has-export-modifier.ts b/src/transformer/util/ensure-node-has-export-modifier.ts index 55c32dd..8f86e21 100644 --- a/src/transformer/util/ensure-node-has-export-modifier.ts +++ b/src/transformer/util/ensure-node-has-export-modifier.ts @@ -1,12 +1,10 @@ -import {BeforeVisitorContext} from "../before/visitor/before-visitor-context"; +import {BeforeVisitorContext} from "../visitor/before-visitor-context"; import {TS} from "../../type/ts"; import {shouldDebug} from "./should-debug"; -import {CompatFactory} from "../../type/compat-factory"; -import {isNodeFactory} from "./is-node-factory"; -export function ensureNodeHasExportModifier(node: T, context: BeforeVisitorContext, compatFactory: CompatFactory): T { +export function ensureNodeHasExportModifier(node: T, context: BeforeVisitorContext): T { const existingModifierKinds = node.modifiers == null ? [] : node.modifiers.map(m => m.kind); - const {typescript} = context; + const {typescript, factory} = context; const declarationName = typescript.getNameOfDeclaration(node); if (declarationName != null && typescript.isIdentifier(declarationName)) { // If the declaration name is part of the exports of the SourceFile, return the node as it is @@ -22,10 +20,10 @@ export function ensureNodeHasExportModifier(node: return node as unknown as T; } - const newModifiers = [compatFactory.createModifier(typescript.SyntaxKind.ExportKeyword), ...existingModifierKinds.map(kind => compatFactory.createModifier(kind) as TS.Modifier)]; + const newModifiers = [context.factory.createModifier(typescript.SyntaxKind.ExportKeyword), ...existingModifierKinds.map(kind => factory.createModifier(kind) as TS.Modifier)]; if (typescript.isFunctionDeclaration(node)) { - return compatFactory.updateFunctionDeclaration( + return context.factory.updateFunctionDeclaration( node, node.decorators, newModifiers, @@ -37,21 +35,19 @@ export function ensureNodeHasExportModifier(node: node.body ) as unknown as T; } else if (typescript.isFunctionExpression(node)) { - return compatFactory.updateFunctionExpression(node, newModifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) as unknown as T; + return context.factory.updateFunctionExpression(node, newModifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, node.body) as unknown as T; } else if (typescript.isClassDeclaration(node)) { - return compatFactory.updateClassDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) as unknown as T; + return context.factory.updateClassDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) as unknown as T; } else if (typescript.isClassExpression(node)) { - return (isNodeFactory(compatFactory) - ? compatFactory.updateClassExpression(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) - : compatFactory.updateClassExpression(node, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members)) as unknown as T; + return context.factory.updateClassExpression(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) as unknown as T; } else if (typescript.isVariableStatement(node)) { - return compatFactory.updateVariableStatement(node, newModifiers, node.declarationList) as unknown as T; + return context.factory.updateVariableStatement(node, newModifiers, node.declarationList) as unknown as T; } else if (typescript.isEnumDeclaration(node)) { - return compatFactory.updateEnumDeclaration(node, node.decorators, newModifiers, node.name, node.members) as unknown as T; + return context.factory.updateEnumDeclaration(node, node.decorators, newModifiers, node.name, node.members) as unknown as T; } else if (typescript.isInterfaceDeclaration(node)) { - return compatFactory.updateInterfaceDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) as unknown as T; + return context.factory.updateInterfaceDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.heritageClauses, node.members) as unknown as T; } else if (typescript.isTypeAliasDeclaration(node)) { - return compatFactory.updateTypeAliasDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.type) as unknown as T; + return context.factory.updateTypeAliasDeclaration(node, node.decorators, newModifiers, node.name, node.typeParameters, node.type) as unknown as T; } // Only throw if debugging is active diff --git a/src/transformer/util/get-best-body-in-scope.ts b/src/transformer/util/get-best-body-in-scope.ts index bfee298..c83ef55 100644 --- a/src/transformer/util/get-best-body-in-scope.ts +++ b/src/transformer/util/get-best-body-in-scope.ts @@ -1,9 +1,8 @@ import {getExportsData} from "./get-exports-data"; import {isExpression} from "./is-expression"; import {walkThroughFillerNodes} from "./walk-through-filler-nodes"; -import {BeforeVisitorOptions} from "../before/visitor/before-visitor-options"; +import {BeforeVisitorOptions} from "../visitor/before-visitor-options"; import {TS} from "../../type/ts"; -import {isNodeFactory} from "./is-node-factory"; function hasExportAssignments(node: TS.Node, exportsName: string, typescript: typeof TS): boolean { const result = typescript.forEachChild(node, nextNode => { @@ -20,8 +19,8 @@ function hasExportAssignments(node: TS.Node, exportsName: string, typescript: ty return result != null ? result : false; } -export function getBestBodyInScope({node, context, compatFactory}: BeforeVisitorOptions): TS.Node | undefined { - const {typescript} = context; +export function getBestBodyInScope({node, context}: BeforeVisitorOptions): TS.Node | undefined { + const {typescript, factory} = context; if (!typescript.isSourceFile(node)) { return node; } @@ -43,7 +42,7 @@ export function getBestBodyInScope({node, context, compatFactory}: BeforeVisitor if (hasExportAssignments(secondArgument.body, firstBodyParameter.name.text, typescript)) { context.exportsName = firstBodyParameter.name.text; - return (isNodeFactory(compatFactory) ? compatFactory.updateSourceFile : compatFactory.updateSourceFileNode)( + return factory.updateSourceFile( node, [...secondArgument.body.statements, ...node.statements.slice(1)], node.isDeclarationFile, diff --git a/src/transformer/util/get-module-exports-from-require-data-in-context.ts b/src/transformer/util/get-module-exports-from-require-data-in-context.ts index 70a5052..b716f8d 100644 --- a/src/transformer/util/get-module-exports-from-require-data-in-context.ts +++ b/src/transformer/util/get-module-exports-from-require-data-in-context.ts @@ -1,8 +1,8 @@ import {IsRequireCallResult} from "./is-require-call"; import {ModuleExports} from "../module-exports/module-exports"; import {BUILT_IN_MODULE_MAP, isBuiltInModule} from "../built-in/built-in-module-map"; -import {transformSourceFile} from "../before/transform-source-file"; -import {BeforeVisitorContext} from "../before/visitor/before-visitor-context"; +import {transformSourceFile} from "../transform-source-file"; +import {BeforeVisitorContext} from "../visitor/before-visitor-context"; /** * Tries to get or potentially parse module exports based on the given data in the given context @@ -41,12 +41,9 @@ export function getModuleExportsFromRequireDataInContext(data: IsRequireCallResu moduleExports = transformSourceFile( typescript.createSourceFile(resolvedModuleSpecifier, resolvedModuleSpecifierText, typescript.ScriptTarget.ESNext, true, typescript.ScriptKind.TS), { - baseVisitorContext: { - ...context, - onlyExports: true - } - }, - context.transformationContext + ...context, + onlyExports: true + } ).exports; } } diff --git a/src/transformer/util/is-node-factory.ts b/src/transformer/util/is-node-factory.ts deleted file mode 100644 index 4606bf5..0000000 --- a/src/transformer/util/is-node-factory.ts +++ /dev/null @@ -1,6 +0,0 @@ -import {TS} from "../../type/ts"; -import {CompatFactory} from "../../type/compat-factory"; - -export function isNodeFactory(compatFactory: CompatFactory): compatFactory is TS.NodeFactory { - return !("updateSourceFileNode" in compatFactory); -} diff --git a/src/transformer/util/should-skip-emit.ts b/src/transformer/util/should-skip-emit.ts index fa4bd33..af9fcae 100644 --- a/src/transformer/util/should-skip-emit.ts +++ b/src/transformer/util/should-skip-emit.ts @@ -1,4 +1,4 @@ -import {isNotEmittedStatement} from "../before/visitor/visit/is-not-emitted-statement"; +import {isNotEmittedStatement} from "../visitor/visit/is-not-emitted-statement"; import {TS} from "../../type/ts"; /** diff --git a/src/transformer/visitor-context.ts b/src/transformer/visitor-context.ts index 435e274..12f7960 100644 --- a/src/transformer/visitor-context.ts +++ b/src/transformer/visitor-context.ts @@ -14,5 +14,16 @@ export interface VisitorContext extends TaskOptions { * A cache that reuses previous lookups for module specifiers to avoid unnecessary duplication of work */ resolveCache: Map; + + /** + * The Node Factory for creating and updating nodes in the tree + */ + factory: TS.NodeFactory; + + /** + * The TypeScript transformation context + */ + transformationContext: TS.TransformationContext; + printer?: TS.Printer; } diff --git a/src/transformer/visitor-options.ts b/src/transformer/visitor-options.ts index eb9f04d..5e1e4a8 100644 --- a/src/transformer/visitor-options.ts +++ b/src/transformer/visitor-options.ts @@ -1,11 +1,9 @@ import {VisitorContinuation} from "./visitor-continuation"; import {VisitorContext} from "./visitor-context"; import {TS} from "../type/ts"; -import {CompatFactory} from "../type/compat-factory"; export interface VisitorOptions { node: T; - compatFactory: CompatFactory; sourceFile: TS.SourceFile; context: VisitorContext; continuation: VisitorContinuation; diff --git a/src/transformer/before/visitor/before-visitor-context.ts b/src/transformer/visitor/before-visitor-context.ts similarity index 88% rename from src/transformer/before/visitor/before-visitor-context.ts rename to src/transformer/visitor/before-visitor-context.ts index 26e05e4..6215dbc 100644 --- a/src/transformer/before/visitor/before-visitor-context.ts +++ b/src/transformer/visitor/before-visitor-context.ts @@ -1,9 +1,8 @@ -import {VisitorContext} from "../../visitor-context"; -import {ModuleExports} from "../../module-exports/module-exports"; -import {TS} from "../../../type/ts"; +import {VisitorContext} from "../visitor-context"; +import {ModuleExports} from "../module-exports/module-exports"; +import {TS} from "../../type/ts"; export interface BeforeVisitorContext extends VisitorContext { - transformationContext: TS.TransformationContext; exportsName: string | undefined; getModuleExportsForPath(path: string): ModuleExports | undefined; addModuleExportsForPath(path: string, exports: ModuleExports): void; diff --git a/src/transformer/before/visitor/before-visitor-options.ts b/src/transformer/visitor/before-visitor-options.ts similarity index 66% rename from src/transformer/before/visitor/before-visitor-options.ts rename to src/transformer/visitor/before-visitor-options.ts index f15ffa5..0b5d72a 100644 --- a/src/transformer/before/visitor/before-visitor-options.ts +++ b/src/transformer/visitor/before-visitor-options.ts @@ -1,6 +1,6 @@ -import {VisitorOptions} from "../../visitor-options"; +import {VisitorOptions} from "../visitor-options"; import {BeforeVisitorContext} from "./before-visitor-context"; -import {TS} from "../../../type/ts"; +import {TS} from "../../type/ts"; export interface BeforeVisitorOptions extends VisitorOptions { context: BeforeVisitorContext; diff --git a/src/transformer/before/visitor/visit/is-not-emitted-statement.ts b/src/transformer/visitor/visit/is-not-emitted-statement.ts similarity index 81% rename from src/transformer/before/visitor/visit/is-not-emitted-statement.ts rename to src/transformer/visitor/visit/is-not-emitted-statement.ts index d0c0826..7e4e753 100644 --- a/src/transformer/before/visitor/visit/is-not-emitted-statement.ts +++ b/src/transformer/visitor/visit/is-not-emitted-statement.ts @@ -1,4 +1,4 @@ -import {TS} from "../../../../type/ts"; +import {TS} from "../../../type/ts"; export function isNotEmittedStatement(node: TS.Node, typescript: typeof TS): node is TS.NotEmittedStatement { return node.kind === typescript.SyntaxKind.NotEmittedStatement; diff --git a/src/transformer/before/visitor/visit/visit-binary-expression.ts b/src/transformer/visitor/visit/visit-binary-expression.ts similarity index 54% rename from src/transformer/before/visitor/visit/visit-binary-expression.ts rename to src/transformer/visitor/visit/visit-binary-expression.ts index 63c80cf..2babb02 100644 --- a/src/transformer/before/visitor/visit/visit-binary-expression.ts +++ b/src/transformer/visitor/visit/visit-binary-expression.ts @@ -1,25 +1,24 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {getExportsData} from "../../../util/get-exports-data"; -import {walkThroughFillerNodes} from "../../../util/walk-through-filler-nodes"; -import {isNamedDeclaration} from "../../../util/is-named-declaration"; -import {ensureNodeHasExportModifier} from "../../../util/ensure-node-has-export-modifier"; -import {nodeContainsSuper} from "../../../util/node-contains-super"; -import {addExportModifier} from "../../../util/add-export-modifier"; -import {isRequireCall} from "../../../util/is-require-call"; -import {getModuleExportsFromRequireDataInContext} from "../../../util/get-module-exports-from-require-data-in-context"; -import {isExpression} from "../../../util/is-expression"; -import {findNodeUp} from "../../../util/find-node-up"; -import {getLocalsForBindingName} from "../../../util/get-locals-for-binding-name"; -import {TS} from "../../../../type/ts"; -import {shouldDebug} from "../../../util/should-debug"; -import {isNodeFactory} from "../../../util/is-node-factory"; +import {getExportsData} from "../../util/get-exports-data"; +import {walkThroughFillerNodes} from "../../util/walk-through-filler-nodes"; +import {isNamedDeclaration} from "../../util/is-named-declaration"; +import {ensureNodeHasExportModifier} from "../../util/ensure-node-has-export-modifier"; +import {nodeContainsSuper} from "../../util/node-contains-super"; +import {addExportModifier} from "../../util/add-export-modifier"; +import {isRequireCall} from "../../util/is-require-call"; +import {getModuleExportsFromRequireDataInContext} from "../../util/get-module-exports-from-require-data-in-context"; +import {isExpression} from "../../util/is-expression"; +import {findNodeUp} from "../../util/find-node-up"; +import {getLocalsForBindingName} from "../../util/get-locals-for-binding-name"; +import {TS} from "../../../type/ts"; +import {shouldDebug} from "../../util/should-debug"; /** * Visits the given BinaryExpression */ -export function visitBinaryExpression({node, sourceFile, context, continuation, compatFactory}: BeforeVisitorOptions): TS.VisitResult { +export function visitBinaryExpression({node, sourceFile, context, continuation}: BeforeVisitorOptions): TS.VisitResult { // Check if the left-hand side contains exports. For example: 'exports = ...' or 'exports.foo = 1' or event 'module.exports = 1' - const {typescript} = context; + const {typescript, factory} = context; const exportsData = getExportsData(node.left, context.exportsName, typescript); const right = walkThroughFillerNodes(node.right, typescript); if (exportsData == null) return node; @@ -30,7 +29,7 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, // For example: 'const foo = module.exports = ...' const variableDeclarationParent = findNodeUp(node, typescript.isVariableDeclaration); const variableDeclarationLocal = - variableDeclarationParent != null ? compatFactory.createIdentifier(getLocalsForBindingName(variableDeclarationParent.name, typescript)[0]) : undefined; + variableDeclarationParent != null ? factory.createIdentifier(getLocalsForBindingName(variableDeclarationParent.name, typescript)[0]) : undefined; // This is something like for example 'exports = ...', 'module.exports = ...', 'exports.default', or 'module.exports.default' if (exportsData.property == null || exportsData.property === "default") { @@ -51,7 +50,7 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, // Only generate the default export if the module don't already include a default export if (!context.isDefaultExported) { context.markDefaultAsExported(); - context.addTrailingStatements(compatFactory.createExportAssignment(undefined, undefined, false, exportedSymbol)); + context.addTrailingStatements(factory.createExportAssignment(undefined, undefined, false, exportedSymbol)); } return variableDeclarationParent != null ? node.right : undefined; @@ -82,14 +81,10 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, if (typescript.isShorthandPropertyAssignment(property)) { context.markLocalAsExported(propertyName); - elements.push(compatFactory.createShorthandPropertyAssignment(propertyName, property.objectAssignmentInitializer)); + elements.push(factory.createShorthandPropertyAssignment(propertyName, property.objectAssignmentInitializer)); - const namedExports = compatFactory.createNamedExports([compatFactory.createExportSpecifier(undefined, propertyName)]); - statements.push( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports, undefined) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports, undefined) - ); + const namedExports = factory.createNamedExports([factory.createExportSpecifier(undefined, propertyName)]); + statements.push(factory.createExportDeclaration(undefined, undefined, false, namedExports, undefined)); } // If it is a PropertyAssignment that points to an Identifier, we know that it holds a reference to some root-level identifier. @@ -97,34 +92,23 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, else if (typescript.isPropertyAssignment(property) && typescript.isIdentifier(property.initializer)) { context.markLocalAsExported(propertyName); - elements.push(compatFactory.createPropertyAssignment(propertyName, compatFactory.createIdentifier(property.initializer.text))); + elements.push(factory.createPropertyAssignment(propertyName, factory.createIdentifier(property.initializer.text))); - const namedExports = compatFactory.createNamedExports([ + const namedExports = factory.createNamedExports([ propertyName === property.initializer.text - ? compatFactory.createExportSpecifier(undefined, propertyName) - : compatFactory.createExportSpecifier(property.initializer.text, propertyName) + ? factory.createExportSpecifier(undefined, propertyName) + : factory.createExportSpecifier(property.initializer.text, propertyName) ]); - statements.push( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports, undefined) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports, undefined) - ); + statements.push(factory.createExportDeclaration(undefined, undefined, false, namedExports, undefined)); } else if (context.isIdentifierFree(propertyName) && typescript.isPropertyAssignment(property) && !nodeContainsSuper(property.initializer, typescript)) { context.addLocal(propertyName); - elements.push(compatFactory.createShorthandPropertyAssignment(propertyName)); + elements.push(factory.createShorthandPropertyAssignment(propertyName)); statements.push( - compatFactory.createVariableStatement( - [compatFactory.createModifier(typescript.SyntaxKind.ExportKeyword)], - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(propertyName, undefined, undefined, property.initializer) - : compatFactory.createVariableDeclaration(propertyName, undefined, property.initializer) - ], - typescript.NodeFlags.Const - ) + factory.createVariableStatement( + [factory.createModifier(typescript.SyntaxKind.ExportKeyword)], + factory.createVariableDeclarationList([factory.createVariableDeclaration(propertyName, undefined, undefined, property.initializer)], typescript.NodeFlags.Const) ) ); } @@ -137,12 +121,12 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, !nodeContainsSuper(property, typescript) ) { context.addLocal(propertyName); - elements.push(compatFactory.createShorthandPropertyAssignment(propertyName)); + elements.push(factory.createShorthandPropertyAssignment(propertyName)); statements.push( - compatFactory.createFunctionDeclaration( + factory.createFunctionDeclaration( property.decorators, - addExportModifier(property.modifiers, typescript, compatFactory), + addExportModifier(property.modifiers, context), property.asteriskToken, property.name, property.typeParameters, @@ -164,22 +148,16 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, context.markLocalAsExported(propertyName); statements.push( - compatFactory.createVariableStatement( - [compatFactory.createModifier(typescript.SyntaxKind.ExportKeyword)], - compatFactory.createVariableDeclarationList( + factory.createVariableStatement( + [factory.createModifier(typescript.SyntaxKind.ExportKeyword)], + factory.createVariableDeclarationList( [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration( - propertyName, - undefined, - undefined, - compatFactory.createPropertyAccessExpression(compatFactory.createIdentifier(moduleExportsIdentifierName), propertyName) - ) - : compatFactory.createVariableDeclaration( - propertyName, - undefined, - compatFactory.createPropertyAccess(compatFactory.createIdentifier(moduleExportsIdentifierName), propertyName) - ) + factory.createVariableDeclaration( + propertyName, + undefined, + undefined, + factory.createPropertyAccessExpression(factory.createIdentifier(moduleExportsIdentifierName), propertyName) + ) ], typescript.NodeFlags.Const ) @@ -195,21 +173,17 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, if (moduleExportsIdentifierName != null) { // Create a VariableStatement that exports the ObjectLiteral statements.push( - compatFactory.createVariableStatement( + factory.createVariableStatement( undefined, - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(moduleExportsIdentifierName, undefined, undefined, compatFactory.createObjectLiteralExpression(elements, true)) - : compatFactory.createVariableDeclaration(moduleExportsIdentifierName, undefined, compatFactory.createObjectLiteral(elements, true)) - ], + factory.createVariableDeclarationList( + [factory.createVariableDeclaration(moduleExportsIdentifierName, undefined, undefined, factory.createObjectLiteralExpression(elements, true))], typescript.NodeFlags.Const ) ) ); if (!context.isDefaultExported) { - statements.push(compatFactory.createExportAssignment(undefined, undefined, false, compatFactory.createIdentifier(moduleExportsIdentifierName))); + statements.push(factory.createExportAssignment(undefined, undefined, false, factory.createIdentifier(moduleExportsIdentifierName))); context.markDefaultAsExported(); } @@ -217,10 +191,8 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, // Otherwise, we don't need to assign it to a VariableStatement. Instead, we can just provide the ObjectLiteralExpression to the ExportAssignment directly. else if (!context.isDefaultExported) { - const defaultExportInitializer = isNodeFactory(compatFactory) - ? compatFactory.createObjectLiteralExpression(elements, true) - : compatFactory.createObjectLiteral(elements, true); - statements.push(compatFactory.createExportAssignment(undefined, undefined, false, defaultExportInitializer)); + const defaultExportInitializer = factory.createObjectLiteralExpression(elements, true); + statements.push(factory.createExportAssignment(undefined, undefined, false, defaultExportInitializer)); } // Return all of the statements @@ -244,7 +216,7 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, const replacementNode = variableDeclarationParent != null ? continuationResult : undefined; const exportedSymbol = variableDeclarationLocal != null ? variableDeclarationLocal : continuationResult; - context.addTrailingStatements(compatFactory.createExportAssignment(undefined, undefined, false, exportedSymbol)); + context.addTrailingStatements(factory.createExportAssignment(undefined, undefined, false, exportedSymbol)); return replacementNode; } } @@ -266,28 +238,20 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, // Otherwise, take the exports from that module else { const moduleExports = getModuleExportsFromRequireDataInContext(requireData, context); - const moduleSpecifierExpression = compatFactory.createStringLiteral(moduleSpecifier); + const moduleSpecifierExpression = factory.createStringLiteral(moduleSpecifier); // If the module has a default export, or if we know nothing about it, // export the default export from that module if (!context.isDefaultExported && (moduleExports == null || moduleExports.hasDefaultExport)) { context.markDefaultAsExported(); - const namedExports = compatFactory.createNamedExports([compatFactory.createExportSpecifier(undefined, "default")]); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports, moduleSpecifierExpression) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports, moduleSpecifierExpression) - ); + const namedExports = factory.createNamedExports([factory.createExportSpecifier(undefined, "default")]); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, namedExports, moduleSpecifierExpression)); return undefined; } // Otherwise, export the entire module (e.g. all named exports) else { - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, undefined, moduleSpecifierExpression) - : compatFactory.createExportDeclaration(undefined, undefined, undefined, moduleSpecifierExpression) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, undefined, moduleSpecifierExpression)); return undefined; } } @@ -305,17 +269,13 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, return undefined; } - const namedExports = compatFactory.createNamedExports([ + const namedExports = factory.createNamedExports([ local === variableDeclarationLocal.text - ? compatFactory.createExportSpecifier(undefined, compatFactory.createIdentifier(local)) - : compatFactory.createExportSpecifier(variableDeclarationLocal.text, compatFactory.createIdentifier(local)) + ? factory.createExportSpecifier(undefined, factory.createIdentifier(local)) + : factory.createExportSpecifier(variableDeclarationLocal.text, factory.createIdentifier(local)) ]); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, namedExports)); return continuationResult; } @@ -324,24 +284,20 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, else if (typescript.isIdentifier(right)) { const local = exportsData.property; if (!context.isLocalExported(local)) { - const namedExports = compatFactory.createNamedExports([ + const namedExports = factory.createNamedExports([ local === right.text - ? compatFactory.createExportSpecifier(undefined, compatFactory.createIdentifier(local)) - : compatFactory.createExportSpecifier(right.text, compatFactory.createIdentifier(local)) + ? factory.createExportSpecifier(undefined, factory.createIdentifier(local)) + : factory.createExportSpecifier(right.text, factory.createIdentifier(local)) ]); context.markLocalAsExported(local); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, namedExports)); } return undefined; } // Otherwise, this is something like 'exports.foo = function foo () {}' else if (isNamedDeclaration(right, typescript) && right.name != null && typescript.isIdentifier(right.name) && exportsData.property === right.name.text) { - context.addTrailingStatements(ensureNodeHasExportModifier(right, context, compatFactory) as unknown as TS.Statement); + context.addTrailingStatements(ensureNodeHasExportModifier(right, context) as unknown as TS.Statement); return undefined; } @@ -357,53 +313,39 @@ export function visitBinaryExpression({node, sourceFile, context, continuation, context.markLocalAsExported(exportsData.property); if (typescript.isIdentifier(continuationResult)) { - const namedExports = compatFactory.createNamedExports([ + const namedExports = factory.createNamedExports([ continuationResult.text === exportsData.property - ? compatFactory.createExportSpecifier(undefined, compatFactory.createIdentifier(exportsData.property)) - : compatFactory.createExportSpecifier(compatFactory.createIdentifier(continuationResult.text), compatFactory.createIdentifier(exportsData.property)) + ? factory.createExportSpecifier(undefined, factory.createIdentifier(exportsData.property)) + : factory.createExportSpecifier(factory.createIdentifier(continuationResult.text), factory.createIdentifier(exportsData.property)) ]); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports, undefined) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports, undefined) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, namedExports, undefined)); } else { const freeIdentifier = context.getFreeIdentifier(exportsData.property); // If it is free, we can simply add an export modifier in front of the expression if (freeIdentifier === exportsData.property) { context.addTrailingStatements( - compatFactory.createVariableStatement( - [compatFactory.createModifier(typescript.SyntaxKind.ExportKeyword)], - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(exportsData.property, undefined, undefined, continuationResult as TS.Expression) - : compatFactory.createVariableDeclaration(exportsData.property, undefined, continuationResult as TS.Expression) - ], + factory.createVariableStatement( + [factory.createModifier(typescript.SyntaxKind.ExportKeyword)], + factory.createVariableDeclarationList( + [factory.createVariableDeclaration(exportsData.property, undefined, undefined, continuationResult as TS.Expression)], typescript.NodeFlags.Const ) ) ); } else { - const namedExports = compatFactory.createNamedExports([compatFactory.createExportSpecifier(freeIdentifier, exportsData.property)]); + const namedExports = factory.createNamedExports([factory.createExportSpecifier(freeIdentifier, exportsData.property)]); // If it isn't, we'll need to bind it to a variable with the free name, but then export it under the original one context.addTrailingStatements( - compatFactory.createVariableStatement( + factory.createVariableStatement( undefined, - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(freeIdentifier, undefined, undefined, continuationResult as TS.Expression) - : compatFactory.createVariableDeclaration(freeIdentifier, undefined, continuationResult as TS.Expression) - ], + factory.createVariableDeclarationList( + [factory.createVariableDeclaration(freeIdentifier, undefined, undefined, continuationResult as TS.Expression)], typescript.NodeFlags.Const ) ), - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, namedExports, undefined) - : compatFactory.createExportDeclaration(undefined, undefined, namedExports, undefined) + factory.createExportDeclaration(undefined, undefined, false, namedExports, undefined) ); } } diff --git a/src/transformer/before/visitor/visit/visit-call-expression.ts b/src/transformer/visitor/visit/visit-call-expression.ts similarity index 68% rename from src/transformer/before/visitor/visit/visit-call-expression.ts rename to src/transformer/visitor/visit/visit-call-expression.ts index 27643b3..c14c901 100644 --- a/src/transformer/before/visitor/visit/visit-call-expression.ts +++ b/src/transformer/visitor/visit/visit-call-expression.ts @@ -1,14 +1,13 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {isRequireCall} from "../../../util/is-require-call"; -import {findNodeUp} from "../../../util/find-node-up"; -import {isStatementOrDeclaration} from "../../../util/is-statement-or-declaration"; -import {isStatement} from "../../../util/is-statement"; -import {generateNameFromModuleSpecifier} from "../../../util/generate-name-from-module-specifier"; -import {getModuleExportsFromRequireDataInContext} from "../../../util/get-module-exports-from-require-data-in-context"; -import {TS} from "../../../../type/ts"; -import {shouldDebug} from "../../../util/should-debug"; -import {walkThroughFillerNodes} from "../../../util/walk-through-filler-nodes"; -import {isNodeFactory} from "../../../util/is-node-factory"; +import {isRequireCall} from "../../util/is-require-call"; +import {findNodeUp} from "../../util/find-node-up"; +import {isStatementOrDeclaration} from "../../util/is-statement-or-declaration"; +import {isStatement} from "../../util/is-statement"; +import {generateNameFromModuleSpecifier} from "../../util/generate-name-from-module-specifier"; +import {getModuleExportsFromRequireDataInContext} from "../../util/get-module-exports-from-require-data-in-context"; +import {TS} from "../../../type/ts"; +import {shouldDebug} from "../../util/should-debug"; +import {walkThroughFillerNodes} from "../../util/walk-through-filler-nodes"; /** * Visits the given CallExpression @@ -16,14 +15,14 @@ import {isNodeFactory} from "../../../util/is-node-factory"; * @param options * @returns */ -export function visitCallExpression({node, childContinuation, sourceFile, context, compatFactory}: BeforeVisitorOptions): TS.VisitResult { +export function visitCallExpression({node, childContinuation, sourceFile, context}: BeforeVisitorOptions): TS.VisitResult { if (context.onlyExports) { return childContinuation(node); } // Check if the node represents a require(...) call. const requireData = isRequireCall(node, sourceFile, context); - const {typescript} = context; + const {typescript, factory} = context; // If it doesn't proceed without applying any transformations if (!requireData.match) { @@ -58,7 +57,7 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex if (expressionStatementParent != null) { // Only add the import if there isn't already an import within the SourceFile of the entire module without any bindings if (!context.isModuleSpecifierImportedWithoutLocals(moduleSpecifier)) { - context.addImport(compatFactory.createImportDeclaration(undefined, undefined, undefined, compatFactory.createStringLiteral(transformedModuleSpecifier))); + context.addImport(factory.createImportDeclaration(undefined, undefined, undefined, factory.createStringLiteral(transformedModuleSpecifier))); } // Drop this CallExpression @@ -71,15 +70,13 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // rather than generating a new unnecessary import if (context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { const local = context.getLocalForDefaultImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } else { - const identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + const identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); - const importClause = isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined); + const importClause = factory.createImportClause(false, identifier, undefined); - context.addImport(compatFactory.createImportDeclaration(undefined, undefined, importClause, compatFactory.createStringLiteral(transformedModuleSpecifier))); + context.addImport(factory.createImportDeclaration(undefined, undefined, importClause, factory.createStringLiteral(transformedModuleSpecifier))); // Replace the CallExpression by the identifier return identifier; @@ -122,31 +119,27 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // If the default export is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import if (moduleExports.hasDefaultExport && context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { - identifier = compatFactory.createIdentifier(context.getLocalForDefaultImportFromModule(moduleSpecifier)!); + identifier = factory.createIdentifier(context.getLocalForDefaultImportFromModule(moduleSpecifier)!); } // If the namespace is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import else if (!moduleExports.hasDefaultExport && context.hasLocalForNamespaceImportFromModule(moduleSpecifier)) { - identifier = compatFactory.createIdentifier(context.getLocalForNamespaceImportFromModule(moduleSpecifier)!); + identifier = factory.createIdentifier(context.getLocalForNamespaceImportFromModule(moduleSpecifier)!); } else { - identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined) + factory.createImportClause(false, identifier, undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(identifier)) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(identifier)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(identifier)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); } @@ -154,10 +147,10 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // Replace the CallExpression by an ObjectLiteral that can be accessed by the wrapping Element- or PropertyAccessExpression const objectLiteralProperties = [ identifier.text !== rightValue - ? compatFactory.createPropertyAssignment(rightValue, compatFactory.createIdentifier(identifier.text)) - : compatFactory.createShorthandPropertyAssignment(compatFactory.createIdentifier(identifier.text)) + ? factory.createPropertyAssignment(rightValue, factory.createIdentifier(identifier.text)) + : factory.createShorthandPropertyAssignment(factory.createIdentifier(identifier.text)) ]; - return isNodeFactory(compatFactory) ? compatFactory.createObjectLiteralExpression(objectLiteralProperties) : compatFactory.createObjectLiteral(objectLiteralProperties); + return factory.createObjectLiteralExpression(objectLiteralProperties); } // Otherwise, use the right value as the ImportSpecifier for a new import. @@ -183,19 +176,17 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // If that binding isn't free within the context, import it as another local name importBindingName = context.getFreeIdentifier(importBindingPropertyName); - const namedImports = compatFactory.createNamedImports([ + const namedImports = factory.createNamedImports([ importBindingPropertyName === importBindingName ? // If the property name is free within the context, don't alias the import - compatFactory.createImportSpecifier(undefined, compatFactory.createIdentifier(importBindingPropertyName)) + factory.createImportSpecifier(undefined, factory.createIdentifier(importBindingPropertyName)) : // Otherwise, import it aliased by another name that is free within the context - compatFactory.createImportSpecifier(compatFactory.createIdentifier(importBindingPropertyName), compatFactory.createIdentifier(importBindingName)) + factory.createImportSpecifier(factory.createIdentifier(importBindingPropertyName), factory.createIdentifier(importBindingName)) ]); - const importClause = isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, namedImports) - : compatFactory.createImportClause(undefined, namedImports); + const importClause = factory.createImportClause(false, undefined, namedImports); - context.addImport(compatFactory.createImportDeclaration(undefined, undefined, importClause, compatFactory.createStringLiteral(transformedModuleSpecifier))); + context.addImport(factory.createImportDeclaration(undefined, undefined, importClause, factory.createStringLiteral(transformedModuleSpecifier))); } // If the 'require(...)[]' or 'require(...).' expression is part of an ExpressionStatement @@ -204,10 +195,10 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex if (expressionStatementParent == null) { const objectLiteralProperties = [ importBindingName !== rightValue - ? compatFactory.createPropertyAssignment(rightValue, compatFactory.createIdentifier(importBindingName)) - : compatFactory.createShorthandPropertyAssignment(compatFactory.createIdentifier(importBindingName)) + ? factory.createPropertyAssignment(rightValue, factory.createIdentifier(importBindingName)) + : factory.createShorthandPropertyAssignment(factory.createIdentifier(importBindingName)) ]; - return isNodeFactory(compatFactory) ? compatFactory.createObjectLiteralExpression(objectLiteralProperties) : compatFactory.createObjectLiteral(objectLiteralProperties); + return factory.createObjectLiteralExpression(objectLiteralProperties); } else { return undefined; } @@ -231,34 +222,30 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // rather than generating a new unnecessary import if (moduleExports.hasDefaultExport && context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { const local = context.getLocalForDefaultImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // If the namespace is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import else if (!moduleExports.hasDefaultExport && context.hasLocalForNamespaceImportFromModule(moduleSpecifier)) { const local = context.getLocalForNamespaceImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // Otherwise proceed as planned else { - const identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + const identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined) + factory.createImportClause(false, identifier, undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(identifier)) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(identifier)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(identifier)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); return identifier; @@ -285,19 +272,19 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex const local = context.getLocalForNamedImportPropertyNameFromModule(element.name.text, moduleSpecifier)!; skippedImportSpecifiers.push( local === element.name.text - ? compatFactory.createImportSpecifier(undefined, compatFactory.createIdentifier(local)) - : compatFactory.createImportSpecifier(compatFactory.createIdentifier(element.name.text), compatFactory.createIdentifier(local)) + ? factory.createImportSpecifier(undefined, factory.createIdentifier(local)) + : factory.createImportSpecifier(factory.createIdentifier(element.name.text), factory.createIdentifier(local)) ); } // If the name is free, just import it as it is else if (context.isIdentifierFree(element.name.text)) { context.addLocal(element.name.text); - importSpecifiers.push(compatFactory.createImportSpecifier(undefined, compatFactory.createIdentifier(element.name.text))); + importSpecifiers.push(factory.createImportSpecifier(undefined, factory.createIdentifier(element.name.text))); } else { // Otherwise, import it under an aliased name const alias = context.getFreeIdentifier(element.name.text); - importSpecifiers.push(compatFactory.createImportSpecifier(compatFactory.createIdentifier(element.name.text), compatFactory.createIdentifier(alias))); + importSpecifiers.push(factory.createImportSpecifier(factory.createIdentifier(element.name.text), factory.createIdentifier(alias))); } } } @@ -312,10 +299,10 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // If the name is free, just import it as it is if (context.isIdentifierFree(element.propertyName.text)) { context.addLocal(element.propertyName.text); - importSpecifiers.push(compatFactory.createImportSpecifier(undefined, compatFactory.createIdentifier(element.propertyName.text))); + importSpecifiers.push(factory.createImportSpecifier(undefined, factory.createIdentifier(element.propertyName.text))); } else { const alias = context.getFreeIdentifier(element.propertyName.text); - importSpecifiers.push(compatFactory.createImportSpecifier(compatFactory.createIdentifier(element.propertyName.text), compatFactory.createIdentifier(alias))); + importSpecifiers.push(factory.createImportSpecifier(factory.createIdentifier(element.propertyName.text), factory.createIdentifier(alias))); } } } @@ -327,34 +314,30 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // rather than generating a new unnecessary import if (moduleExports.hasDefaultExport && context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { const local = context.getLocalForDefaultImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // If the namespace is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import else if (!moduleExports.hasDefaultExport && context.hasLocalForNamespaceImportFromModule(moduleSpecifier)) { const local = context.getLocalForNamespaceImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // Otherwise proceed as planned else { - const identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + const identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined) + factory.createImportClause(false, identifier, undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(identifier)) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(identifier)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(identifier)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); return identifier; @@ -366,23 +349,21 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex else { if (importSpecifiers.length > 0) { context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamedImports(importSpecifiers)) - : compatFactory.createImportClause(undefined, compatFactory.createNamedImports(importSpecifiers)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamedImports(importSpecifiers)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); } const objectLiteralProperties = [...importSpecifiers, ...skippedImportSpecifiers].map(specifier => specifier.propertyName != null - ? compatFactory.createPropertyAssignment(specifier.propertyName.text, compatFactory.createIdentifier(specifier.name.text)) - : compatFactory.createShorthandPropertyAssignment(compatFactory.createIdentifier(specifier.name.text)) + ? factory.createPropertyAssignment(specifier.propertyName.text, factory.createIdentifier(specifier.name.text)) + : factory.createShorthandPropertyAssignment(factory.createIdentifier(specifier.name.text)) ); - return isNodeFactory(compatFactory) ? compatFactory.createObjectLiteralExpression(objectLiteralProperties) : compatFactory.createObjectLiteral(objectLiteralProperties); + return factory.createObjectLiteralExpression(objectLiteralProperties); } } } @@ -403,34 +384,30 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // rather than generating a new unnecessary import if (moduleExports.hasDefaultExport && context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { const local = context.getLocalForDefaultImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // If the namespace is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import else if (!moduleExports.hasDefaultExport && context.hasLocalForNamespaceImportFromModule(moduleSpecifier)) { const local = context.getLocalForNamespaceImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // Otherwise proceed as planned else { - const identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + const identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined) + factory.createImportClause(false, identifier, undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(identifier)) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(identifier)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(identifier)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); return identifier; @@ -448,34 +425,30 @@ export function visitCallExpression({node, childContinuation, sourceFile, contex // rather than generating a new unnecessary import if (moduleExports.hasDefaultExport && context.hasLocalForDefaultImportFromModule(moduleSpecifier)) { const local = context.getLocalForDefaultImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // If the namespace is already imported, get the local binding name for it and create an identifier for it // rather than generating a new unnecessary import else if (!moduleExports.hasDefaultExport && context.hasLocalForNamespaceImportFromModule(moduleSpecifier)) { const local = context.getLocalForNamespaceImportFromModule(moduleSpecifier)!; - return compatFactory.createIdentifier(local); + return factory.createIdentifier(local); } // Otherwise, proceed as planned else { - const identifier = compatFactory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); + const identifier = factory.createIdentifier(context.getFreeIdentifier(generateNameFromModuleSpecifier(moduleSpecifier))); context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, identifier, undefined) - : compatFactory.createImportClause(identifier, undefined) + factory.createImportClause(false, identifier, undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(identifier)) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(identifier)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(identifier)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); return identifier; diff --git a/src/transformer/before/visitor/visit/visit-export-assignment.ts b/src/transformer/visitor/visit/visit-export-assignment.ts similarity index 88% rename from src/transformer/before/visitor/visit/visit-export-assignment.ts rename to src/transformer/visitor/visit/visit-export-assignment.ts index cc9b2bd..b794e20 100644 --- a/src/transformer/before/visitor/visit/visit-export-assignment.ts +++ b/src/transformer/visitor/visit/visit-export-assignment.ts @@ -1,5 +1,5 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {TS} from "../../../../type/ts"; +import {TS} from "../../../type/ts"; /** * Visits the given ExportAssignment diff --git a/src/transformer/before/visitor/visit/visit-export-declaration.ts b/src/transformer/visitor/visit/visit-export-declaration.ts similarity index 95% rename from src/transformer/before/visitor/visit/visit-export-declaration.ts rename to src/transformer/visitor/visit/visit-export-declaration.ts index e220cef..af0ddb3 100644 --- a/src/transformer/before/visitor/visit/visit-export-declaration.ts +++ b/src/transformer/visitor/visit/visit-export-declaration.ts @@ -1,5 +1,5 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {TS} from "../../../../type/ts"; +import {TS} from "../../../type/ts"; /** * Visits the given ExportDeclaration diff --git a/src/transformer/before/visitor/visit/visit-import-and-export-declarations.ts b/src/transformer/visitor/visit/visit-import-and-export-declarations.ts similarity index 83% rename from src/transformer/before/visitor/visit/visit-import-and-export-declarations.ts rename to src/transformer/visitor/visit/visit-import-and-export-declarations.ts index 7bf2334..9994db6 100644 --- a/src/transformer/before/visitor/visit/visit-import-and-export-declarations.ts +++ b/src/transformer/visitor/visit/visit-import-and-export-declarations.ts @@ -2,11 +2,11 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; import {visitImportDeclaration} from "./visit-import-declaration"; import {visitExportDeclaration} from "./visit-export-declaration"; import {visitExportAssignment} from "./visit-export-assignment"; -import {hasExportModifier} from "../../../util/has-export-modifier"; -import {hasDefaultExportModifier} from "../../../util/has-default-export-modifier"; -import {isDeclaration} from "../../../util/is-declaration"; -import {getLocalsForBindingName} from "../../../util/get-locals-for-binding-name"; -import {TS} from "../../../../type/ts"; +import {hasExportModifier} from "../../util/has-export-modifier"; +import {hasDefaultExportModifier} from "../../util/has-default-export-modifier"; +import {isDeclaration} from "../../util/is-declaration"; +import {getLocalsForBindingName} from "../../util/get-locals-for-binding-name"; +import {TS} from "../../../type/ts"; /** * Visits the given Node diff --git a/src/transformer/before/visitor/visit/visit-import-declaration.ts b/src/transformer/visitor/visit/visit-import-declaration.ts similarity index 87% rename from src/transformer/before/visitor/visit/visit-import-declaration.ts rename to src/transformer/visitor/visit/visit-import-declaration.ts index cf8195e..a31df81 100644 --- a/src/transformer/before/visitor/visit/visit-import-declaration.ts +++ b/src/transformer/visitor/visit/visit-import-declaration.ts @@ -1,5 +1,5 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {TS} from "../../../../type/ts"; +import {TS} from "../../../type/ts"; /** * Visits the given ImportDeclaration diff --git a/src/transformer/before/visitor/visit/visit-node.ts b/src/transformer/visitor/visit/visit-node.ts similarity index 92% rename from src/transformer/before/visitor/visit/visit-node.ts rename to src/transformer/visitor/visit/visit-node.ts index 45b4203..2c3ce5e 100644 --- a/src/transformer/before/visitor/visit/visit-node.ts +++ b/src/transformer/visitor/visit/visit-node.ts @@ -3,8 +3,8 @@ import {visitCallExpression} from "./visit-call-expression"; import {visitBinaryExpression} from "./visit-binary-expression"; import {visitVariableDeclaration} from "./visit-variable-declaration"; import {visitVariableDeclarationList} from "./visit-variable-declaration-list"; -import {getBestBodyInScope} from "../../../util/get-best-body-in-scope"; -import {TS} from "../../../../type/ts"; +import {getBestBodyInScope} from "../../util/get-best-body-in-scope"; +import {TS} from "../../../type/ts"; /** * Visits the given Node diff --git a/src/transformer/before/visitor/visit/visit-variable-declaration-list.ts b/src/transformer/visitor/visit/visit-variable-declaration-list.ts similarity index 79% rename from src/transformer/before/visitor/visit/visit-variable-declaration-list.ts rename to src/transformer/visitor/visit/visit-variable-declaration-list.ts index fa43a2b..814e8d6 100644 --- a/src/transformer/before/visitor/visit/visit-variable-declaration-list.ts +++ b/src/transformer/visitor/visit/visit-variable-declaration-list.ts @@ -1,16 +1,16 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; import {isNotEmittedStatement} from "./is-not-emitted-statement"; -import {TS} from "../../../../type/ts"; +import {TS} from "../../../type/ts"; /** * Visits the given VariableDeclarationList */ -export function visitVariableDeclarationList({node, childContinuation, context, compatFactory}: BeforeVisitorOptions): TS.VisitResult { +export function visitVariableDeclarationList({node, childContinuation, context}: BeforeVisitorOptions): TS.VisitResult { if (context.onlyExports) { return childContinuation(node); } - const {typescript} = context; + const {typescript, factory} = context; const continuationResult = childContinuation(node); // If the result isn't a new VariableDeclarationList, return that result @@ -24,5 +24,5 @@ export function visitVariableDeclarationList({node, childContinuation, context, if (remainingDeclarations.length === 0) return continuationResult; // Otherwise, return an updated version of the declaration list, preserving only those declarations that should be emitted - return compatFactory.updateVariableDeclarationList(node, remainingDeclarations); + return factory.updateVariableDeclarationList(node, remainingDeclarations); } diff --git a/src/transformer/before/visitor/visit/visit-variable-declaration.ts b/src/transformer/visitor/visit/visit-variable-declaration.ts similarity index 57% rename from src/transformer/before/visitor/visit/visit-variable-declaration.ts rename to src/transformer/visitor/visit/visit-variable-declaration.ts index 50e66e4..67b3c68 100644 --- a/src/transformer/before/visitor/visit/visit-variable-declaration.ts +++ b/src/transformer/visitor/visit/visit-variable-declaration.ts @@ -1,22 +1,21 @@ import {BeforeVisitorOptions} from "../before-visitor-options"; -import {isRequireCall} from "../../../util/is-require-call"; -import {walkThroughFillerNodes} from "../../../util/walk-through-filler-nodes"; -import {getModuleExportsFromRequireDataInContext} from "../../../util/get-module-exports-from-require-data-in-context"; -import {TS} from "../../../../type/ts"; -import {willReassignIdentifier} from "../../../util/will-be-reassigned"; -import {hasExportModifier} from "../../../util/has-export-modifier"; -import {findNodeUp} from "../../../util/find-node-up"; -import {isNodeFactory} from "../../../util/is-node-factory"; +import {isRequireCall} from "../../util/is-require-call"; +import {walkThroughFillerNodes} from "../../util/walk-through-filler-nodes"; +import {getModuleExportsFromRequireDataInContext} from "../../util/get-module-exports-from-require-data-in-context"; +import {TS} from "../../../type/ts"; +import {willReassignIdentifier} from "../../util/will-be-reassigned"; +import {hasExportModifier} from "../../util/has-export-modifier"; +import {findNodeUp} from "../../util/find-node-up"; /** * Visits the given VariableDeclaration */ -export function visitVariableDeclaration({node, childContinuation, sourceFile, context, compatFactory}: BeforeVisitorOptions): TS.VisitResult { +export function visitVariableDeclaration({node, childContinuation, sourceFile, context}: BeforeVisitorOptions): TS.VisitResult { if (context.onlyExports || node.initializer == null) { return childContinuation(node); } - const {typescript} = context; + const {typescript, factory} = context; // Most sophisticated require(...) handling comes from the CallExpression visitor, but this Visitor is for rewriting simple // 'foo = require("bar")' or '{foo} = require("bar")' as well as '{foo: bar} = require("bar")' expressions @@ -65,50 +64,36 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c // Otherwise, the 'foo = require("bar")' VariableDeclaration is part of an Exported VariableStatement such as 'export const foo = require("bar")', // and it should preferably be converted into an ExportDeclaration else if (statement != null && hasExportModifier(statement, typescript)) { - const moduleSpecifierExpression = compatFactory.createStringLiteral(transformedModuleSpecifier); + const moduleSpecifierExpression = factory.createStringLiteral(transformedModuleSpecifier); if (moduleExports == null || moduleExports.hasDefaultExport) { - const exportClause = compatFactory.createNamedExports([ - compatFactory.createExportSpecifier(node.name.text === "default" ? undefined : compatFactory.createIdentifier("default"), compatFactory.createIdentifier(node.name.text)) + const exportClause = factory.createNamedExports([ + factory.createExportSpecifier(node.name.text === "default" ? undefined : factory.createIdentifier("default"), factory.createIdentifier(node.name.text)) ]); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, exportClause, moduleSpecifierExpression) - : compatFactory.createExportDeclaration(undefined, undefined, exportClause, moduleSpecifierExpression) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, exportClause, moduleSpecifierExpression)); return undefined; } // Otherwise, if the TypeScript version supports named namespace exports - else if (compatFactory.createNamespaceExport != null) { - const exportClause = compatFactory.createNamespaceExport(compatFactory.createIdentifier(node.name.text)); + else if (factory.createNamespaceExport != null) { + const exportClause = factory.createNamespaceExport(factory.createIdentifier(node.name.text)); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, exportClause, moduleSpecifierExpression) - : compatFactory.createExportDeclaration(undefined, undefined, exportClause, moduleSpecifierExpression) - ); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, exportClause, moduleSpecifierExpression)); return undefined; } // Otherwise, for older TypeScript versions, we'll have to first import and then re-export the namespace else { context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(compatFactory.createIdentifier(node.name.text))) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(compatFactory.createIdentifier(node.name.text))), + factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(node.name.text))), moduleSpecifierExpression ) ); - const exportClause = compatFactory.createNamedExports([compatFactory.createExportSpecifier(undefined, compatFactory.createIdentifier(node.name.text))]); - context.addTrailingStatements( - isNodeFactory(compatFactory) - ? compatFactory.createExportDeclaration(undefined, undefined, false, exportClause) - : compatFactory.createExportDeclaration(undefined, undefined, exportClause) - ); + const exportClause = factory.createNamedExports([factory.createExportSpecifier(undefined, factory.createIdentifier(node.name.text))]); + context.addTrailingStatements(factory.createExportDeclaration(undefined, undefined, false, exportClause)); return undefined; } } @@ -120,33 +105,25 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c const newName = willReassign ? context.getFreeIdentifier(node.name.text, true) : node.name.text; context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, moduleExports == null || moduleExports.hasDefaultExport ? // Import the default if it has any (or if we don't know if it has) - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, compatFactory.createIdentifier(newName), undefined) - : compatFactory.createImportClause(compatFactory.createIdentifier(newName), undefined) + factory.createImportClause(false, factory.createIdentifier(newName), undefined) : // Otherwise, import the entire namespace - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamespaceImport(compatFactory.createIdentifier(newName))) - : compatFactory.createImportClause(undefined, compatFactory.createNamespaceImport(compatFactory.createIdentifier(newName))), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamespaceImport(factory.createIdentifier(newName))), + factory.createStringLiteral(transformedModuleSpecifier) ) ); if (willReassign) { // Now, immediately add a local mutable variable with the correct name context.addLeadingStatements( - compatFactory.createVariableStatement( + factory.createVariableStatement( undefined, - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(node.name.text, undefined, undefined, compatFactory.createIdentifier(newName)) - : compatFactory.createVariableDeclaration(node.name.text, undefined, compatFactory.createIdentifier(newName)) - ], + factory.createVariableDeclarationList( + [factory.createVariableDeclaration(node.name.text, undefined, undefined, factory.createIdentifier(newName))], typescript.NodeFlags.Let ) ) @@ -170,7 +147,7 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c return childContinuation(node); } - importSpecifiers.push(compatFactory.createImportSpecifier(undefined, compatFactory.createIdentifier(element.name.text))); + importSpecifiers.push(factory.createImportSpecifier(undefined, factory.createIdentifier(element.name.text))); } // This will be something like '{foo: bar} = require("bar")' @@ -181,7 +158,7 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c return childContinuation(node); } - importSpecifiers.push(compatFactory.createImportSpecifier(compatFactory.createIdentifier(element.propertyName.text), compatFactory.createIdentifier(element.name.text))); + importSpecifiers.push(factory.createImportSpecifier(factory.createIdentifier(element.propertyName.text), factory.createIdentifier(element.name.text))); } else { // Opt out and proceed with the child continuation for more sophisticated handling return childContinuation(node); @@ -197,29 +174,18 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c const propertyName = importSpecifier.propertyName ?? importSpecifier.name; const newName = context.getFreeIdentifier(importSpecifier.name.text, true); - const namedImports = compatFactory.createNamedImports([ - compatFactory.createImportSpecifier(compatFactory.createIdentifier(propertyName.text), compatFactory.createIdentifier(newName)) - ]); + const namedImports = factory.createNamedImports([factory.createImportSpecifier(factory.createIdentifier(propertyName.text), factory.createIdentifier(newName))]); context.addImport( - compatFactory.createImportDeclaration( - undefined, - undefined, - isNodeFactory(compatFactory) ? compatFactory.createImportClause(false, undefined, namedImports) : compatFactory.createImportClause(undefined, namedImports), - compatFactory.createStringLiteral(transformedModuleSpecifier) - ) + factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, namedImports), factory.createStringLiteral(transformedModuleSpecifier)) ); // Now, immediately add a local mutable variable with the correct name context.addLeadingStatements( - compatFactory.createVariableStatement( + factory.createVariableStatement( undefined, - compatFactory.createVariableDeclarationList( - [ - isNodeFactory(compatFactory) - ? compatFactory.createVariableDeclaration(importSpecifier.name.text, undefined, undefined, compatFactory.createIdentifier(newName)) - : compatFactory.createVariableDeclaration(importSpecifier.name.text, undefined, compatFactory.createIdentifier(newName)) - ], + factory.createVariableDeclarationList( + [factory.createVariableDeclaration(importSpecifier.name.text, undefined, undefined, factory.createIdentifier(newName))], typescript.NodeFlags.Let ) ) @@ -228,13 +194,11 @@ export function visitVariableDeclaration({node, childContinuation, sourceFile, c if (otherImportSpecifiers.length > 0) { context.addImport( - compatFactory.createImportDeclaration( + factory.createImportDeclaration( undefined, undefined, - isNodeFactory(compatFactory) - ? compatFactory.createImportClause(false, undefined, compatFactory.createNamedImports(otherImportSpecifiers)) - : compatFactory.createImportClause(undefined, compatFactory.createNamedImports(otherImportSpecifiers)), - compatFactory.createStringLiteral(transformedModuleSpecifier) + factory.createImportClause(false, undefined, factory.createNamedImports(otherImportSpecifiers)), + factory.createStringLiteral(transformedModuleSpecifier) ) ); } diff --git a/src/type/compat-factory.ts b/src/type/compat-factory.ts deleted file mode 100644 index ea73755..0000000 --- a/src/type/compat-factory.ts +++ /dev/null @@ -1,3 +0,0 @@ -import {TS} from "./ts"; - -export type CompatFactory = TS.NodeFactory | typeof TS;