From cf7f47e7a2d4c02895dc181744dfad061291d79d Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sat, 23 Jan 2021 17:40:53 +1100 Subject: [PATCH 01/26] build(husky): reconfigure husky failed to notice a previous change bumped husky a major version; new version has migration steps that haven't been performed yet --- .husky/.gitignore | 1 + .husky/commit-msg | 4 ++++ .husky/pre-commit | 5 +++++ package.json | 9 ++------- yarn.lock | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .husky/.gitignore create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 00000000..31354ec1 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 00000000..ce7e3a8c --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname $0)/_/husky.sh" + +yarn run commitlint --edit $1 diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..c687fe72 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname $0)/_/husky.sh" + +yarn run lint-staged +yarn test diff --git a/package.json b/package.json index 918284c7..f7012b30 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ ], "description": "Provides an API for easily transforming Delphi Forms", "scripts": { + "postinstall": "husky install", "ci": "yarn --frozen-lockfile && yarn run compile && yarn run lint:check && yarn run format:check && yarn test && yarn docs", "lint": "eslint --ignore-path .gitignore \"**/*.{js,ts}\"", "lint:fix": "yarn lint --fix", @@ -38,7 +39,7 @@ "eslint-plugin-jest": "^23.0.0", "eslint-plugin-node": "^11.0.0", "execa": "^4.0.0", - "husky": "^5.0.0", + "husky": "^5.0.6", "jest": "^26.0.0", "jest-junit": "^10.0.0", "lint-staged": "^10.0.3", @@ -66,12 +67,6 @@ "prettier --ignore-path .gitignore --write" ] }, - "husky": { - "hooks": { - "pre-commit": "lint-staged && yarn test", - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } - }, "engines": { "node": ">=8.3.0" }, diff --git a/yarn.lock b/yarn.lock index 6d57d875..4ec5cbb6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4360,7 +4360,7 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" -husky@^5.0.0: +husky@^5.0.6: version "5.0.6" resolved "https://registry.yarnpkg.com/husky/-/husky-5.0.6.tgz#27dbefe8603c6c0912fd89a3a67edfed9fac8bb9" integrity sha512-SM+evfvcHT3rAYJKvPlatz3L5RqzgeM6xIvDjhs8VuhKj6iKqFDOt/Ov8sPjvWuE4FDB385gJBwWXRj7G3c1hg== From 9853a00843d92075d851d7a7813a108ca2b467eb Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sat, 23 Jan 2021 17:50:01 +1100 Subject: [PATCH 02/26] fix: set node minimum version to 8.3.0 Previously only had this set in the top level package, but the minimum version there does not get propogated to any of the sub-packages BREAKING CHANGE: set node minimum version to 8.3.0 --- packages/@postdfm/ast/package.json | 3 +++ packages/@postdfm/ast2dfm/package.json | 3 +++ packages/@postdfm/dfm2ast/package.json | 3 +++ packages/postdfm/package.json | 3 +++ 4 files changed, 12 insertions(+) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index 3c694e37..5a1793fa 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -18,6 +18,9 @@ "/dist", "README.md" ], + "engines": { + "node": ">=8.3.0" + }, "publishConfig": { "access": "public" } diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index 6bda6b19..e1ff9a4a 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -21,6 +21,9 @@ "/dist", "README.md" ], + "engines": { + "node": ">=8.3.0" + }, "publishConfig": { "access": "public" } diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index ea2d4f8b..adad5099 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -23,6 +23,9 @@ "/dist", "README.md" ], + "engines": { + "node": ">=8.3.0" + }, "publishConfig": { "access": "public" } diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index 813591e8..ef92cc5e 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -33,6 +33,9 @@ "dist/", "README.md" ], + "engines": { + "node": ">=8.3.0" + }, "publishConfig": { "access": "public" } From 734fd5edcbe4c1e315196aac8fe181edc06a64b5 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sun, 24 Jan 2021 14:39:45 +1100 Subject: [PATCH 03/26] build(prettier): upgrade prettier --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f7012b30..8add9f09 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "jest-junit": "^10.0.0", "lint-staged": "^10.0.3", "nearley": "^2.16.0", - "prettier": "^1.16.4", + "prettier": "^2.2.1", "read-pkg": "^5.0.0", "semantic-release": "^17.3.1", "ts-jest": "^26.4.4", diff --git a/yarn.lock b/yarn.lock index 4ec5cbb6..777f4c3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7428,10 +7428,10 @@ prepend-http@^2.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= -prettier@^1.16.4: - version "1.19.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" - integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" + integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== pretty-format@^24.9.0: version "24.9.0" From 03e36e6018d6d40064b3445adee2cd1e93688896 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sun, 24 Jan 2021 14:48:33 +1100 Subject: [PATCH 04/26] style(prettier): rerun prettier --- .eslintrc.js | 2 +- .github/ISSUE_TEMPLATE/bug_report.md | 50 +- .github/ISSUE_TEMPLATE/feature_request.md | 22 +- README.md | 8 +- .../parse/boundary-keyword/ast.json | 134 +- .../__fixtures__/parse/empty-file/ast.json | 12 +- .../__fixtures__/parse/empty-object/ast.json | 42 +- __test__/__fixtures__/parse/lists/ast.json | 856 ++++----- __test__/__fixtures__/parse/no-type/ast.json | 36 +- __test__/__fixtures__/parse/objects/ast.json | 522 +++--- .../__fixtures__/parse/properties/ast.json | 640 +++---- __test__/__fixtures__/parse/strings/ast.json | 328 ++-- .../__fixtures__/parse/weird-spacing/ast.json | 1644 ++++++++--------- .../transform/hello-world/transformer.js | 13 +- commitlint.config.js | 6 +- eslint.config.js | 90 +- jest.config.js | 12 +- packages/@postdfm/ast/.eslintrc.js | 2 +- packages/@postdfm/ast/README.md | 24 +- packages/@postdfm/ast/__test__/item.test.ts | 38 +- packages/@postdfm/ast/__test__/list.test.ts | 150 +- .../@postdfm/ast/__test__/property.test.ts | 48 +- packages/@postdfm/ast/__test__/value.test.ts | 314 ++-- packages/@postdfm/ast/src/astNode.ts | 22 +- packages/@postdfm/ast/src/astRaws.ts | 8 +- packages/@postdfm/ast/src/astType.ts | 44 +- packages/@postdfm/ast/src/index.ts | 70 +- packages/@postdfm/ast/src/item.ts | 36 +- packages/@postdfm/ast/src/keywords.ts | 2 +- .../@postdfm/ast/src/list/binaryStringList.ts | 18 +- .../@postdfm/ast/src/list/identifierList.ts | 18 +- packages/@postdfm/ast/src/list/itemList.ts | 18 +- packages/@postdfm/ast/src/list/list.ts | 32 +- packages/@postdfm/ast/src/list/variantList.ts | 18 +- packages/@postdfm/ast/src/objectKind.ts | 10 +- packages/@postdfm/ast/src/property.ts | 40 +- .../ast/src/value/binaryStringValue.ts | 16 +- .../@postdfm/ast/src/value/booleanValue.ts | 16 +- .../@postdfm/ast/src/value/controlString.ts | 16 +- .../@postdfm/ast/src/value/currencyValue.ts | 18 +- .../@postdfm/ast/src/value/dateTimeValue.ts | 18 +- .../@postdfm/ast/src/value/doubleValue.ts | 18 +- packages/@postdfm/ast/src/value/float.ts | 10 +- .../@postdfm/ast/src/value/hexCodeValue.ts | 16 +- .../@postdfm/ast/src/value/identifierValue.ts | 16 +- .../@postdfm/ast/src/value/integerValue.ts | 16 +- .../@postdfm/ast/src/value/literalString.ts | 16 +- .../@postdfm/ast/src/value/singleValue.ts | 18 +- .../@postdfm/ast/src/value/stringValue.ts | 18 +- .../@postdfm/ast/src/value/stringValuePart.ts | 16 +- packages/@postdfm/ast/src/value/value.ts | 20 +- packages/@postdfm/ast/typedoc.config.js | 6 +- packages/@postdfm/ast2dfm/.eslintrc.js | 2 +- packages/@postdfm/ast2dfm/README.md | 24 +- .../@postdfm/ast2dfm/__test__/broken/ast.json | 6 +- .../ast2dfm/__test__/broken/index.test.ts | 28 +- .../ast2dfm/__test__/fixtures/index.test.ts | 46 +- packages/@postdfm/ast2dfm/src/index.ts | 20 +- packages/@postdfm/ast2dfm/src/stringifier.ts | 564 +++--- packages/@postdfm/ast2dfm/typedoc.config.js | 6 +- packages/@postdfm/dfm2ast/.eslintrc.js | 2 +- packages/@postdfm/dfm2ast/README.md | 24 +- .../dfm2ast/__test__/fixtures/index.test.ts | 44 +- packages/@postdfm/dfm2ast/src/index.ts | 50 +- packages/@postdfm/dfm2ast/typedoc.config.js | 6 +- packages/postdfm/.eslintrc.js | 2 +- packages/postdfm/README.md | 284 +-- .../postdfm/__test__/broken/index.test.ts | 82 +- .../postdfm/__test__/fixtures/index.test.ts | 140 +- .../postdfm/__test__/options/index.test.ts | 126 +- .../postdfm/__test__/options/transformer.js | 2 +- packages/postdfm/src/index.ts | 4 +- packages/postdfm/typedoc.config.js | 6 +- release.config.js | 20 +- typedoc.js | 26 +- 75 files changed, 3548 insertions(+), 3549 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index be9be32a..8e608c0b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1 +1 @@ -module.exports = require("./eslint.config")(); +module.exports = require("./eslint.config")(); diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 22dd342e..3b90dca5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,25 +1,25 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "[Bug] " -labels: "bug" -assignees: "" ---- - -### What versions am I using of... - -- `nodejs`: x.x.x -- `npm`/`yarn`: x.x.x -- `postdfm`: x.x.x - -### What did I do? - -### What was I expecting? - -### What happened instead? - -### What do I think is the problem? - -### Am I willing to make a pull request with failing tests to help speed up the fix? - -### Am I willing to make a pull request with the fix as well? +--- +name: Bug report +about: Create a report to help us improve +title: "[Bug] " +labels: "bug" +assignees: "" +--- + +### What versions am I using of... + +- `nodejs`: x.x.x +- `npm`/`yarn`: x.x.x +- `postdfm`: x.x.x + +### What did I do? + +### What was I expecting? + +### What happened instead? + +### What do I think is the problem? + +### Am I willing to make a pull request with failing tests to help speed up the fix? + +### Am I willing to make a pull request with the fix as well? diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index e08b4fca..28743099 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,11 +1,11 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: "[Feature] " -labels: "feature" -assignees: "" ---- - -### What doesn't `postdfm` do that I would like it to? - -### Am I willing to make a pull request with an implementation of the feature? +--- +name: Feature request +about: Suggest an idea for this project +title: "[Feature] " +labels: "feature" +assignees: "" +--- + +### What doesn't `postdfm` do that I would like it to? + +### Am I willing to make a pull request with an implementation of the feature? diff --git a/README.md b/README.md index 3f9ad465..b6f1b517 100644 --- a/README.md +++ b/README.md @@ -51,16 +51,16 @@ const cisDfm = fs.readFileSync( const runner = postdfm({ transformers: [ - function(ast) { + function (ast) { //transform and return the ast return transformedAst; - } - ] + }, + ], }); const transDfm = runner.processSync(dfm, { //filename used for reporting errors - from: "cis.dfm" + from: "cis.dfm", }); fs.writeFileSync("trans.dfm", transDfm); diff --git a/__test__/__fixtures__/parse/boundary-keyword/ast.json b/__test__/__fixtures__/parse/boundary-keyword/ast.json index c1a076a2..0671a904 100644 --- a/__test__/__fixtures__/parse/boundary-keyword/ast.json +++ b/__test__/__fixtures__/parse/boundary-keyword/ast.json @@ -1,67 +1,67 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "kind": "object", - "name": "Outer", - "type": "TOuter", - "properties": [], - "children": [ - { - "astType": "object", - "kind": "object", - "name": "Problem", - "type": "TProblem", - "properties": [ - { - "astType": "property", - "name": "ProblemProperty", - "value": { - "astType": "identifier", - "value": "ErrorEnd" - }, - "raws": { - "afterName": " ", - "beforeValue": " " - } - } - ], - "children": [ - { - "astType": "object", - "kind": "object", - "name": "Inner", - "type": "TInner", - "properties": [], - "children": [], - "raws": { - "afterName": "", - "beforeType": " ", - "beforeName": " ", - "beforeEnd": "\r\n " - } - } - ], - "raws": { - "afterName": "", - "beforeType": " ", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n " - } - } - ], - "raws": { - "afterName": "", - "beforeType": " ", - "beforeName": " ", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n" - } - }, - "raws": { - "before": "", - "after": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "kind": "object", + "name": "Outer", + "type": "TOuter", + "properties": [], + "children": [ + { + "astType": "object", + "kind": "object", + "name": "Problem", + "type": "TProblem", + "properties": [ + { + "astType": "property", + "name": "ProblemProperty", + "value": { + "astType": "identifier", + "value": "ErrorEnd" + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + } + ], + "children": [ + { + "astType": "object", + "kind": "object", + "name": "Inner", + "type": "TInner", + "properties": [], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeEnd": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n" + } + }, + "raws": { + "before": "", + "after": "" + } +} diff --git a/__test__/__fixtures__/parse/empty-file/ast.json b/__test__/__fixtures__/parse/empty-file/ast.json index 66c77dc9..c5a6828b 100644 --- a/__test__/__fixtures__/parse/empty-file/ast.json +++ b/__test__/__fixtures__/parse/empty-file/ast.json @@ -1,6 +1,6 @@ -{ - "astType": "root", - "raws": { - "before": "" - } -} +{ + "astType": "root", + "raws": { + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/empty-object/ast.json b/__test__/__fixtures__/parse/empty-object/ast.json index 2ee1d055..bde6ead2 100644 --- a/__test__/__fixtures__/parse/empty-object/ast.json +++ b/__test__/__fixtures__/parse/empty-object/ast.json @@ -1,21 +1,21 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [], - "kind": "object", - "name": "Empty", - "properties": [], - "raws": { - "afterName": "", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeType": " " - }, - "type": "TEmpty" - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [], + "kind": "object", + "name": "Empty", + "properties": [], + "raws": { + "afterName": "", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeType": " " + }, + "type": "TEmpty" + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/lists/ast.json b/__test__/__fixtures__/parse/lists/ast.json index 91963fea..b7584246 100644 --- a/__test__/__fixtures__/parse/lists/ast.json +++ b/__test__/__fixtures__/parse/lists/ast.json @@ -1,428 +1,428 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [], - "kind": "object", - "name": "ListForm", - "properties": [ - { - "astType": "property", - "name": "Options", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "identifierList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": "\r\n " - }, - "values": [ - { - "astType": "identifier", - "raws": { - "after": "" - }, - "value": "dgTitles" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "\r\n " - }, - "value": "dg_Indicator" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgColumnResize" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "\r\n " - }, - "value": "dgColLines" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgRowLines" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "\r\n " - }, - "value": "dgTabs" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgRowSelect" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "\r\n " - }, - "value": "dgConfirmDelete" - }, - { - "astType": "identifier", - "raws": { - "before": "\r\n " - }, - "value": "dgCancelOnExit" - } - ] - } - }, - { - "astType": "property", - "name": "EmptyOptions", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "identifierList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - }, - { - "astType": "property", - "name": "Strings", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "variantList", - "raws": { - "afterOpen": " ", - "beforeClose": "\r\n " - }, - "values": [ - { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "this is string." - } - ] - }, - { - "astType": "string", - "raws": { - "before": "\r\n " - }, - "value": [ - { - "astType": "literalString", - "value": "and another one..." - }, - { - "astType": "literalString", - "raws": { - "before": "\r\n + " - }, - "value": "and another one..." - }, - { - "astType": "literalString", - "raws": { - "before": "\r\n + " - }, - "value": "now with apostrophe '" - }, - { - "astType": "controlString", - "value": "\r" - }, - { - "astType": "controlString", - "value": "\n" - }, - { - "astType": "literalString", - "value": "how fancy" - } - ] - } - ] - } - }, - { - "astType": "property", - "name": "Variants", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "variantList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": "" - }, - "values": [ - { - "astType": "integer", - "value": "255" - }, - { - "astType": "integer", - "raws": { - "before": "\r\n " - }, - "value": "255" - }, - { - "astType": "integer", - "raws": { - "before": "\r\n " - }, - "value": "255" - }, - { - "astType": "boolean", - "raws": { - "before": "\r\n " - }, - "value": true - }, - { - "astType": "string", - "raws": { - "before": "\r\n " - }, - "value": [ - { - "astType": "literalString", - "value": "Hello World!" - } - ] - }, - { - "astType": "double", - "raws": { - "before": "\r\n " - }, - "value": { - "exponent": "22", - "integer": "45" - } - } - ] - } - }, - { - "astType": "property", - "name": "EmptyVariants", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "variantList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - }, - { - "astType": "property", - "name": "Items", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "itemList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": "" - }, - "values": [ - { - "astType": "item", - "properties": [ - { - "astType": "property", - "name": "Expanded", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": false - } - }, - { - "astType": "property", - "name": "Visible", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - } - ], - "raws": { - "afterItem": "\r\n ", - "beforeEnd": "\r\n " - } - }, - { - "astType": "item", - "properties": [], - "raws": { - "afterItem": "\r\n ", - "before": "\r\n " - } - }, - { - "astType": "item", - "properties": [ - { - "astType": "property", - "name": "Expanded", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": false - } - }, - { - "astType": "property", - "name": "Visible", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - } - ], - "raws": { - "afterItem": "\r\n ", - "before": "\r\n ", - "beforeEnd": "\r\n " - } - } - ] - } - }, - { - "astType": "property", - "name": "EmptyItems", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "itemList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - }, - { - "astType": "property", - "name": "BinaryData", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "binaryStringList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": "\r\n " - }, - "values": [ - { - "astType": "binaryString", - "value": "07544269746D617036550000424D365500000000000036000000280000005500" - }, - { - "astType": "binaryString", - "raws": { - "before": "\r\n " - }, - "value": "000055000000010018000000000000550000C40E0000C40E0000000000000000" - } - ] - } - }, - { - "astType": "property", - "name": "EmptyBinaryData", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "binaryStringList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - } - ], - "raws": { - "afterName": "", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TForm" - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [], + "kind": "object", + "name": "ListForm", + "properties": [ + { + "astType": "property", + "name": "Options", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "identifierList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "\r\n " + }, + "values": [ + { + "astType": "identifier", + "raws": { + "after": "" + }, + "value": "dgTitles" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "\r\n " + }, + "value": "dg_Indicator" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgColumnResize" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "\r\n " + }, + "value": "dgColLines" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgRowLines" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "\r\n " + }, + "value": "dgTabs" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgRowSelect" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "\r\n " + }, + "value": "dgConfirmDelete" + }, + { + "astType": "identifier", + "raws": { + "before": "\r\n " + }, + "value": "dgCancelOnExit" + } + ] + } + }, + { + "astType": "property", + "name": "EmptyOptions", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "identifierList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + }, + { + "astType": "property", + "name": "Strings", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "variantList", + "raws": { + "afterOpen": " ", + "beforeClose": "\r\n " + }, + "values": [ + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "this is string." + } + ] + }, + { + "astType": "string", + "raws": { + "before": "\r\n " + }, + "value": [ + { + "astType": "literalString", + "value": "and another one..." + }, + { + "astType": "literalString", + "raws": { + "before": "\r\n + " + }, + "value": "and another one..." + }, + { + "astType": "literalString", + "raws": { + "before": "\r\n + " + }, + "value": "now with apostrophe '" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "literalString", + "value": "how fancy" + } + ] + } + ] + } + }, + { + "astType": "property", + "name": "Variants", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "variantList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + }, + "values": [ + { + "astType": "integer", + "value": "255" + }, + { + "astType": "integer", + "raws": { + "before": "\r\n " + }, + "value": "255" + }, + { + "astType": "integer", + "raws": { + "before": "\r\n " + }, + "value": "255" + }, + { + "astType": "boolean", + "raws": { + "before": "\r\n " + }, + "value": true + }, + { + "astType": "string", + "raws": { + "before": "\r\n " + }, + "value": [ + { + "astType": "literalString", + "value": "Hello World!" + } + ] + }, + { + "astType": "double", + "raws": { + "before": "\r\n " + }, + "value": { + "exponent": "22", + "integer": "45" + } + } + ] + } + }, + { + "astType": "property", + "name": "EmptyVariants", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "variantList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + }, + { + "astType": "property", + "name": "Items", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "itemList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + }, + "values": [ + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": false + } + }, + { + "astType": "property", + "name": "Visible", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n " + } + }, + { + "astType": "item", + "properties": [], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": false + } + }, + { + "astType": "property", + "name": "Visible", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + } + ], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n ", + "beforeEnd": "\r\n " + } + } + ] + } + }, + { + "astType": "property", + "name": "EmptyItems", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "itemList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + }, + { + "astType": "property", + "name": "BinaryData", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "binaryStringList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "\r\n " + }, + "values": [ + { + "astType": "binaryString", + "value": "07544269746D617036550000424D365500000000000036000000280000005500" + }, + { + "astType": "binaryString", + "raws": { + "before": "\r\n " + }, + "value": "000055000000010018000000000000550000C40E0000C40E0000000000000000" + } + ] + } + }, + { + "astType": "property", + "name": "EmptyBinaryData", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "binaryStringList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + } + ], + "raws": { + "afterName": "", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TForm" + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/no-type/ast.json b/__test__/__fixtures__/parse/no-type/ast.json index f492c9d8..f3557fec 100644 --- a/__test__/__fixtures__/parse/no-type/ast.json +++ b/__test__/__fixtures__/parse/no-type/ast.json @@ -1,18 +1,18 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [], - "kind": "object", - "name": "Empty", - "properties": [], - "raws": { - "beforeEnd": "\r\n", - "beforeName": " " - } - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [], + "kind": "object", + "name": "Empty", + "properties": [], + "raws": { + "beforeEnd": "\r\n", + "beforeName": " " + } + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/objects/ast.json b/__test__/__fixtures__/parse/objects/ast.json index 13178fdc..854d1d94 100644 --- a/__test__/__fixtures__/parse/objects/ast.json +++ b/__test__/__fixtures__/parse/objects/ast.json @@ -1,261 +1,261 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [], - "kind": "object", - "name": "Edit1", - "properties": [], - "raws": { - "afterName": "", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TEdit" - }, - { - "astType": "object", - "children": [], - "kind": "inline", - "name": "Edit2", - "properties": [], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TEdit" - }, - { - "astType": "object", - "children": [], - "kind": "inherited", - "name": "Edit3", - "properties": [], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TEdit" - }, - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [], - "kind": "object", - "name": "DeepTree10", - "properties": [], - "raws": { - "afterName": "", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree9", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree8", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree7", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree6", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree5", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree4", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree3", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree2", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "DeepTree1", - "properties": [], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "TComponent" - } - ], - "kind": "object", - "name": "_Under_Score", - "properties": [], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeType": " " - }, - "type": "_TUnder_Score" - } - ], - "kind": "object", - "name": "BasicForm", - "properties": [ - { - "astType": "property", - "name": "Caption", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Basic Form" - } - ] - } - } - ], - "raws": { - "afterName": "", - "beforeChildren": "\r\n ", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TForm" - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [], + "kind": "object", + "name": "Edit1", + "properties": [], + "raws": { + "afterName": "", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TEdit" + }, + { + "astType": "object", + "children": [], + "kind": "inline", + "name": "Edit2", + "properties": [], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TEdit" + }, + { + "astType": "object", + "children": [], + "kind": "inherited", + "name": "Edit3", + "properties": [], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TEdit" + }, + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [], + "kind": "object", + "name": "DeepTree10", + "properties": [], + "raws": { + "afterName": "", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree9", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree8", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree7", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree6", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree5", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree4", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree3", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree2", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "DeepTree1", + "properties": [], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "TComponent" + } + ], + "kind": "object", + "name": "_Under_Score", + "properties": [], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeType": " " + }, + "type": "_TUnder_Score" + } + ], + "kind": "object", + "name": "BasicForm", + "properties": [ + { + "astType": "property", + "name": "Caption", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Basic Form" + } + ] + } + } + ], + "raws": { + "afterName": "", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TForm" + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/properties/ast.json b/__test__/__fixtures__/parse/properties/ast.json index 46c84938..ab686091 100644 --- a/__test__/__fixtures__/parse/properties/ast.json +++ b/__test__/__fixtures__/parse/properties/ast.json @@ -1,320 +1,320 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [], - "kind": "object", - "name": "Form", - "properties": [ - { - "astType": "property", - "name": "BooleanProperty", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - }, - { - "astType": "property", - "name": "BooleanProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": false - } - }, - { - "astType": "property", - "name": "IntegerProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "integer", - "value": "123456" - } - }, - { - "astType": "property", - "name": "IntegerProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "integer", - "value": "-123456" - } - }, - { - "astType": "property", - "name": "FloatProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "fraction": "456", - "integer": "123" - } - } - }, - { - "astType": "property", - "name": "FloatProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "fraction": "456", - "integer": "-123" - } - } - }, - { - "astType": "property", - "name": "FloatProperty3", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "456", - "integer": "123" - } - } - }, - { - "astType": "property", - "name": "FloatProperty4", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "456", - "integer": "-123" - } - } - }, - { - "astType": "property", - "name": "FloatProperty5", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "56", - "fraction": "34", - "integer": "12" - } - } - }, - { - "astType": "property", - "name": "FloatProperty6", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "56", - "fraction": "34", - "integer": "-12" - } - } - }, - { - "astType": "property", - "name": "SingleProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "single", - "value": { - "integer": "2" - } - } - }, - { - "astType": "property", - "name": "SingleProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "single", - "value": { - "exponent": "5", - "fraction": "4", - "integer": "-2" - } - } - }, - { - "astType": "property", - "name": "DateTimeProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "dateTime", - "value": { - "integer": "3" - } - } - }, - { - "astType": "property", - "name": "DateTimeProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "dateTime", - "value": { - "exponent": "5", - "fraction": "4", - "integer": "-2" - } - } - }, - { - "astType": "property", - "name": "CurrencyProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "currency", - "value": { - "integer": "4" - } - } - }, - { - "astType": "property", - "name": "CurrencyProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "currency", - "value": { - "exponent": "5", - "fraction": "4", - "integer": "-2" - } - } - }, - { - "astType": "property", - "name": "ColorProperty", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "hexCode", - "value": "7F7F7F" - } - }, - { - "astType": "property", - "name": "QualifiedValue", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "identifier", - "value": "TEnum.enEnum" - } - }, - { - "astType": "property", - "name": "Qualified.Property", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - }, - { - "astType": "property", - "name": "Border.Bottom.Style", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "identifier", - "value": "bsSolid" - } - } - ], - "raws": { - "afterName": "", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TForm" - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [], + "kind": "object", + "name": "Form", + "properties": [ + { + "astType": "property", + "name": "BooleanProperty", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + }, + { + "astType": "property", + "name": "BooleanProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": false + } + }, + { + "astType": "property", + "name": "IntegerProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "integer", + "value": "123456" + } + }, + { + "astType": "property", + "name": "IntegerProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "integer", + "value": "-123456" + } + }, + { + "astType": "property", + "name": "FloatProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "fraction": "456", + "integer": "123" + } + } + }, + { + "astType": "property", + "name": "FloatProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "fraction": "456", + "integer": "-123" + } + } + }, + { + "astType": "property", + "name": "FloatProperty3", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "456", + "integer": "123" + } + } + }, + { + "astType": "property", + "name": "FloatProperty4", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "456", + "integer": "-123" + } + } + }, + { + "astType": "property", + "name": "FloatProperty5", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "56", + "fraction": "34", + "integer": "12" + } + } + }, + { + "astType": "property", + "name": "FloatProperty6", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "56", + "fraction": "34", + "integer": "-12" + } + } + }, + { + "astType": "property", + "name": "SingleProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "single", + "value": { + "integer": "2" + } + } + }, + { + "astType": "property", + "name": "SingleProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "single", + "value": { + "exponent": "5", + "fraction": "4", + "integer": "-2" + } + } + }, + { + "astType": "property", + "name": "DateTimeProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "dateTime", + "value": { + "integer": "3" + } + } + }, + { + "astType": "property", + "name": "DateTimeProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "dateTime", + "value": { + "exponent": "5", + "fraction": "4", + "integer": "-2" + } + } + }, + { + "astType": "property", + "name": "CurrencyProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "currency", + "value": { + "integer": "4" + } + } + }, + { + "astType": "property", + "name": "CurrencyProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "currency", + "value": { + "exponent": "5", + "fraction": "4", + "integer": "-2" + } + } + }, + { + "astType": "property", + "name": "ColorProperty", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "hexCode", + "value": "7F7F7F" + } + }, + { + "astType": "property", + "name": "QualifiedValue", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "identifier", + "value": "TEnum.enEnum" + } + }, + { + "astType": "property", + "name": "Qualified.Property", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + }, + { + "astType": "property", + "name": "Border.Bottom.Style", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "identifier", + "value": "bsSolid" + } + } + ], + "raws": { + "afterName": "", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TForm" + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/strings/ast.json b/__test__/__fixtures__/parse/strings/ast.json index bf0438d6..5b2b2022 100644 --- a/__test__/__fixtures__/parse/strings/ast.json +++ b/__test__/__fixtures__/parse/strings/ast.json @@ -1,164 +1,164 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [], - "kind": "object", - "name": "Form", - "properties": [ - { - "astType": "property", - "name": "StringProperty", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "" - } - ] - } - }, - { - "astType": "property", - "name": "StringProperty2", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Hello world!" - } - ] - } - }, - { - "astType": "property", - "name": "StringProperty3", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Hello'world!" - } - ] - } - }, - { - "astType": "property", - "name": "StringProperty3", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Hello" - }, - { - "astType": "literalString", - "raws": { - "before": " + " - }, - "value": "world!" - } - ] - } - }, - { - "astType": "property", - "name": "StringProperty4", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Hello" - }, - { - "astType": "controlString", - "value": "\r" - }, - { - "astType": "controlString", - "value": "\n" - }, - { - "astType": "literalString", - "value": "world!" - } - ] - } - }, - { - "astType": "property", - "name": "StringProperty5", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Hello'" - }, - { - "astType": "controlString", - "value": "\r" - }, - { - "astType": "controlString", - "value": "\n" - }, - { - "astType": "literalString", - "raws": { - "before": " + " - }, - "value": "world!" - } - ] - } - } - ], - "raws": { - "afterName": "", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TForm" - }, - "raws": { - "after": "", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [], + "kind": "object", + "name": "Form", + "properties": [ + { + "astType": "property", + "name": "StringProperty", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "" + } + ] + } + }, + { + "astType": "property", + "name": "StringProperty2", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Hello world!" + } + ] + } + }, + { + "astType": "property", + "name": "StringProperty3", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Hello'world!" + } + ] + } + }, + { + "astType": "property", + "name": "StringProperty3", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Hello" + }, + { + "astType": "literalString", + "raws": { + "before": " + " + }, + "value": "world!" + } + ] + } + }, + { + "astType": "property", + "name": "StringProperty4", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Hello" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "literalString", + "value": "world!" + } + ] + } + }, + { + "astType": "property", + "name": "StringProperty5", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Hello'" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "literalString", + "raws": { + "before": " + " + }, + "value": "world!" + } + ] + } + } + ], + "raws": { + "afterName": "", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TForm" + }, + "raws": { + "after": "", + "before": "" + } +} diff --git a/__test__/__fixtures__/parse/weird-spacing/ast.json b/__test__/__fixtures__/parse/weird-spacing/ast.json index 5be78851..a7a37e3c 100644 --- a/__test__/__fixtures__/parse/weird-spacing/ast.json +++ b/__test__/__fixtures__/parse/weird-spacing/ast.json @@ -1,822 +1,822 @@ -{ - "astType": "root", - "child": { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [], - "kind": "object", - "name": "Image1", - "properties": [ - { - "astType": "property", - "name": "Picture.Data", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "binaryStringList", - "raws": { - "afterOpen": "\r\n\r\n ", - "beforeClose": "\r\n " - }, - "values": [ - { - "astType": "binaryString", - "value": "07544269746D617036550000424D365500000000000036000000280000005500" - }, - { - "astType": "binaryString", - "raws": { - "before": "\r\n\r\n " - }, - "value": "000055000000010018000000000000550000C40E0000C40E0000000000000000" - } - ] - } - }, - { - "astType": "property", - "name": "Picture.MoreData", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "binaryStringList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - } - ], - "raws": { - "afterName": "", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TImage" - }, - { - "astType": "object", - "children": [], - "kind": "inherited", - "name": "ListBox1", - "order": "2", - "properties": [ - { - "astType": "property", - "name": "Items.Strings", - "raws": { - "afterName": " ", - "beforeValue": "\r\n " - }, - "value": { - "astType": "variantList", - "raws": { - "afterOpen": " ", - "beforeClose": "\r\n " - }, - "values": [ - { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "this is string." - } - ] - }, - { - "astType": "string", - "raws": { - "before": " " - }, - "value": [ - { - "astType": "literalString", - "value": "and another one..." - }, - { - "astType": "literalString", - "raws": { - "before": " + " - }, - "value": "and another one..." - }, - { - "astType": "literalString", - "raws": { - "before": "+ " - }, - "value": "now with apostrophe '" - }, - { - "astType": "controlString", - "value": "\r" - }, - { - "astType": "controlString", - "value": "\n" - }, - { - "astType": "literalString", - "value": "how fancy" - } - ] - } - ] - } - }, - { - "astType": "property", - "name": "Items.MoreStrings", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "variantList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - } - ], - "raws": { - "afterName": "", - "afterOrder": "", - "afterType": " ", - "before": "\r\n\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeOrder": "", - "beforeProperties": "\r\n\r\n ", - "beforeType": " " - }, - "type": "TListBox" - }, - { - "astType": "object", - "children": [], - "kind": "object", - "name": "DBGrid1", - "properties": [ - { - "astType": "property", - "name": "Options", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "identifierList", - "raws": { - "afterOpen": "", - "beforeClose": "" - }, - "values": [ - { - "astType": "identifier", - "raws": { - "after": "" - }, - "value": "dgTitles" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dg_Indicator" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "" - }, - "value": "dgColumnResize" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "" - }, - "value": "dgColLines" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": "" - }, - "value": "dgRowLines" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgTabs" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgRowSelect" - }, - { - "astType": "identifier", - "raws": { - "after": "", - "before": " " - }, - "value": "dgConfirmDelete" - }, - { - "astType": "identifier", - "raws": { - "before": " " - }, - "value": "dgCancelOnExit" - } - ] - } - }, - { - "astType": "property", - "name": "MoreOptions", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "identifierList", - "raws": { - "beforeClose": "\r\n\r\n\r\n " - }, - "values": [] - } - }, - { - "astType": "property", - "name": "Columns", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "itemList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": "" - }, - "values": [ - { - "astType": "item", - "properties": [ - { - "astType": "property", - "name": "Expanded", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": false - } - }, - { - "astType": "property", - "name": "Visible", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - } - ], - "raws": { - "afterItem": "\r\n ", - "beforeEnd": "\r\n " - } - }, - { - "astType": "item", - "properties": [], - "raws": { - "afterItem": "\r\n ", - "before": "\r\n " - } - }, - { - "astType": "item", - "properties": [ - { - "astType": "property", - "name": "Expanded", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": false - } - }, - { - "astType": "property", - "name": "Visible", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "boolean", - "value": true - } - } - ], - "raws": { - "afterItem": "\r\n ", - "before": "\r\n ", - "beforeEnd": "\r\n " - } - } - ] - } - }, - { - "astType": "property", - "name": "MoreColumns", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "itemList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - } - ], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TDBGrid" - }, - { - "astType": "object", - "children": [], - "kind": "inline", - "name": "Edit1", - "properties": [ - { - "astType": "property", - "name": "MaxLength", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "20", - "integer": "6" - } - } - }, - { - "astType": "property", - "name": "MinLength", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "1", - "integer": "-20" - } - } - }, - { - "astType": "property", - "name": "SomeOtherLength", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "double", - "value": { - "exponent": "20", - "fraction": "333", - "integer": "45" - } - } - }, - { - "astType": "property", - "name": "Color", - "raws": { - "afterName": " ", - "before": "\r\n\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "hexCode", - "value": "FF0000" - } - }, - { - "astType": "property", - "name": "BackgroundColorStreamer", - "raws": { - "afterName": " ", - "before": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "variantList", - "raws": { - "afterOpen": "\r\n ", - "beforeClose": " " - }, - "values": [ - { - "astType": "integer", - "value": "255" - }, - { - "astType": "integer", - "raws": { - "before": " " - }, - "value": "255" - }, - { - "astType": "integer", - "raws": { - "before": " " - }, - "value": "255" - }, - { - "astType": "boolean", - "raws": { - "before": " " - }, - "value": true - } - ] - } - } - ], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TEdit" - }, - { - "astType": "object", - "children": [], - "kind": "object", - "name": "MyContainer", - "properties": [ - { - "astType": "property", - "name": "Cost", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "currency", - "value": { - "fraction": "5", - "integer": "32" - } - } - }, - { - "astType": "property", - "name": "MinCost", - "raws": { - "afterName": " ", - "before": " ", - "beforeValue": " " - }, - "value": { - "astType": "currency", - "value": { - "integer": "0" - } - } - }, - { - "astType": "property", - "name": "Multiplier", - "raws": { - "afterName": " ", - "before": " ", - "beforeValue": " " - }, - "value": { - "astType": "single", - "value": { - "fraction": "5", - "integer": "12" - } - } - }, - { - "astType": "property", - "name": "Date", - "raws": { - "afterName": " ", - "before": " ", - "beforeValue": " " - }, - "value": { - "astType": "dateTime", - "value": { - "fraction": "1", - "integer": "47000" - } - } - } - ], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": " ", - "beforeName": " ", - "beforeProperties": " ", - "beforeType": " " - }, - "type": "TContainer" - }, - { - "astType": "object", - "children": [], - "kind": "object", - "name": "Edit2", - "properties": [ - { - "astType": "property", - "name": "Value", - "raws": { - "afterName": " ", - "beforeValue": "\r\n " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "Some 'multi' line " - }, - { - "astType": "literalString", - "raws": { - "before": " +\r\n " - }, - "value": "string" - }, - { - "astType": "controlString", - "value": "\r" - }, - { - "astType": "controlString", - "value": "\n" - }, - { - "astType": "controlString", - "raws": { - "before": " +\r\n " - }, - "value": "%" - }, - { - "astType": "literalString", - "value": "hello" - }, - { - "astType": "controlString", - "value": "-" - }, - { - "astType": "literalString", - "value": "world" - } - ] - } - } - ], - "raws": { - "afterName": "", - "before": "\r\n ", - "beforeEnd": "\r\n ", - "beforeName": " ", - "beforeProperties": "\r\n\r\n\r\n ", - "beforeType": " " - }, - "type": "TEdit" - }, - { - "astType": "object", - "children": [ - { - "astType": "object", - "children": [], - "kind": "inline", - "name": "SubEdit", - "properties": [ - { - "astType": "property", - "name": "Value", - "raws": { - "afterName": " ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "" - } - ] - } - }, - { - "astType": "property", - "name": "EditType", - "raws": { - "afterName": " ", - "before": "\r\n", - "beforeValue": " " - }, - "value": { - "astType": "identifier", - "value": "TEdit.TypeEnum.PASSWORD" - } - } - ], - "raws": { - "afterName": "", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeProperties": "\r\n", - "beforeType": " " - }, - "type": "TEdit" - } - ], - "kind": "object", - "name": "SubForm", - "properties": [], - "raws": { - "afterName": "", - "before": "\r\n", - "beforeChildren": "\r\n", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeType": " " - }, - "type": "TForm2" - }, - { - "astType": "object", - "children": [], - "kind": "object", - "name": "Nothing", - "properties": [], - "raws": { - "afterName": "", - "before": "\r\n", - "beforeEnd": "\r\n", - "beforeName": " ", - "beforeType": " " - }, - "type": "_TNothing" - } - ], - "kind": "object", - "name": "Form1", - "properties": [ - { - "astType": "property", - "name": "Left", - "raws": { - "afterName": " ", - "beforeValue": "\r\n\r\n\r\n\r\n " - }, - "value": { - "astType": "integer", - "value": "192" - } - }, - { - "astType": "property", - "name": "Font.Name", - "raws": { - "afterName": " ", - "before": "\r\n ", - "beforeValue": " " - }, - "value": { - "astType": "string", - "value": [ - { - "astType": "literalString", - "value": "MS Sans Serif" - } - ] - } - }, - { - "astType": "property", - "name": "Font.Style", - "raws": { - "afterName": " ", - "before": " ", - "beforeValue": " " - }, - "value": { - "astType": "identifierList", - "raws": { - "beforeClose": "" - }, - "values": [] - } - }, - { - "astType": "property", - "name": "Border.Bottom.Style", - "raws": { - "afterName": " ", - "before": " ", - "beforeValue": " " - }, - "value": { - "astType": "identifier", - "value": "bdSolid" - } - } - ], - "raws": { - "afterName": "", - "beforeChildren": " ", - "beforeEnd": "\r\n", - "beforeName": "\r\n\r\n\r\n\r\n ", - "beforeProperties": "\r\n ", - "beforeType": " " - }, - "type": "TForm1" - }, - "raws": { - "after": "\r\n", - "before": "" - } -} +{ + "astType": "root", + "child": { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [], + "kind": "object", + "name": "Image1", + "properties": [ + { + "astType": "property", + "name": "Picture.Data", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "binaryStringList", + "raws": { + "afterOpen": "\r\n\r\n ", + "beforeClose": "\r\n " + }, + "values": [ + { + "astType": "binaryString", + "value": "07544269746D617036550000424D365500000000000036000000280000005500" + }, + { + "astType": "binaryString", + "raws": { + "before": "\r\n\r\n " + }, + "value": "000055000000010018000000000000550000C40E0000C40E0000000000000000" + } + ] + } + }, + { + "astType": "property", + "name": "Picture.MoreData", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "binaryStringList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + } + ], + "raws": { + "afterName": "", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TImage" + }, + { + "astType": "object", + "children": [], + "kind": "inherited", + "name": "ListBox1", + "order": "2", + "properties": [ + { + "astType": "property", + "name": "Items.Strings", + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + }, + "value": { + "astType": "variantList", + "raws": { + "afterOpen": " ", + "beforeClose": "\r\n " + }, + "values": [ + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "this is string." + } + ] + }, + { + "astType": "string", + "raws": { + "before": " " + }, + "value": [ + { + "astType": "literalString", + "value": "and another one..." + }, + { + "astType": "literalString", + "raws": { + "before": " + " + }, + "value": "and another one..." + }, + { + "astType": "literalString", + "raws": { + "before": "+ " + }, + "value": "now with apostrophe '" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "literalString", + "value": "how fancy" + } + ] + } + ] + } + }, + { + "astType": "property", + "name": "Items.MoreStrings", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "variantList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + } + ], + "raws": { + "afterName": "", + "afterOrder": "", + "afterType": " ", + "before": "\r\n\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeOrder": "", + "beforeProperties": "\r\n\r\n ", + "beforeType": " " + }, + "type": "TListBox" + }, + { + "astType": "object", + "children": [], + "kind": "object", + "name": "DBGrid1", + "properties": [ + { + "astType": "property", + "name": "Options", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "identifierList", + "raws": { + "afterOpen": "", + "beforeClose": "" + }, + "values": [ + { + "astType": "identifier", + "raws": { + "after": "" + }, + "value": "dgTitles" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dg_Indicator" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "" + }, + "value": "dgColumnResize" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "" + }, + "value": "dgColLines" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": "" + }, + "value": "dgRowLines" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgTabs" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgRowSelect" + }, + { + "astType": "identifier", + "raws": { + "after": "", + "before": " " + }, + "value": "dgConfirmDelete" + }, + { + "astType": "identifier", + "raws": { + "before": " " + }, + "value": "dgCancelOnExit" + } + ] + } + }, + { + "astType": "property", + "name": "MoreOptions", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "identifierList", + "raws": { + "beforeClose": "\r\n\r\n\r\n " + }, + "values": [] + } + }, + { + "astType": "property", + "name": "Columns", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "itemList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + }, + "values": [ + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": false + } + }, + { + "astType": "property", + "name": "Visible", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n " + } + }, + { + "astType": "item", + "properties": [], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": false + } + }, + { + "astType": "property", + "name": "Visible", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "boolean", + "value": true + } + } + ], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n ", + "beforeEnd": "\r\n " + } + } + ] + } + }, + { + "astType": "property", + "name": "MoreColumns", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "itemList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + } + ], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TDBGrid" + }, + { + "astType": "object", + "children": [], + "kind": "inline", + "name": "Edit1", + "properties": [ + { + "astType": "property", + "name": "MaxLength", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "20", + "integer": "6" + } + } + }, + { + "astType": "property", + "name": "MinLength", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "1", + "integer": "-20" + } + } + }, + { + "astType": "property", + "name": "SomeOtherLength", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "double", + "value": { + "exponent": "20", + "fraction": "333", + "integer": "45" + } + } + }, + { + "astType": "property", + "name": "Color", + "raws": { + "afterName": " ", + "before": "\r\n\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "hexCode", + "value": "FF0000" + } + }, + { + "astType": "property", + "name": "BackgroundColorStreamer", + "raws": { + "afterName": " ", + "before": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "variantList", + "raws": { + "afterOpen": "\r\n ", + "beforeClose": " " + }, + "values": [ + { + "astType": "integer", + "value": "255" + }, + { + "astType": "integer", + "raws": { + "before": " " + }, + "value": "255" + }, + { + "astType": "integer", + "raws": { + "before": " " + }, + "value": "255" + }, + { + "astType": "boolean", + "raws": { + "before": " " + }, + "value": true + } + ] + } + } + ], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TEdit" + }, + { + "astType": "object", + "children": [], + "kind": "object", + "name": "MyContainer", + "properties": [ + { + "astType": "property", + "name": "Cost", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "currency", + "value": { + "fraction": "5", + "integer": "32" + } + } + }, + { + "astType": "property", + "name": "MinCost", + "raws": { + "afterName": " ", + "before": " ", + "beforeValue": " " + }, + "value": { + "astType": "currency", + "value": { + "integer": "0" + } + } + }, + { + "astType": "property", + "name": "Multiplier", + "raws": { + "afterName": " ", + "before": " ", + "beforeValue": " " + }, + "value": { + "astType": "single", + "value": { + "fraction": "5", + "integer": "12" + } + } + }, + { + "astType": "property", + "name": "Date", + "raws": { + "afterName": " ", + "before": " ", + "beforeValue": " " + }, + "value": { + "astType": "dateTime", + "value": { + "fraction": "1", + "integer": "47000" + } + } + } + ], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": " ", + "beforeName": " ", + "beforeProperties": " ", + "beforeType": " " + }, + "type": "TContainer" + }, + { + "astType": "object", + "children": [], + "kind": "object", + "name": "Edit2", + "properties": [ + { + "astType": "property", + "name": "Value", + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Some 'multi' line " + }, + { + "astType": "literalString", + "raws": { + "before": " +\r\n " + }, + "value": "string" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "controlString", + "raws": { + "before": " +\r\n " + }, + "value": "%" + }, + { + "astType": "literalString", + "value": "hello" + }, + { + "astType": "controlString", + "value": "-" + }, + { + "astType": "literalString", + "value": "world" + } + ] + } + } + ], + "raws": { + "afterName": "", + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeName": " ", + "beforeProperties": "\r\n\r\n\r\n ", + "beforeType": " " + }, + "type": "TEdit" + }, + { + "astType": "object", + "children": [ + { + "astType": "object", + "children": [], + "kind": "inline", + "name": "SubEdit", + "properties": [ + { + "astType": "property", + "name": "Value", + "raws": { + "afterName": " ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "" + } + ] + } + }, + { + "astType": "property", + "name": "EditType", + "raws": { + "afterName": " ", + "before": "\r\n", + "beforeValue": " " + }, + "value": { + "astType": "identifier", + "value": "TEdit.TypeEnum.PASSWORD" + } + } + ], + "raws": { + "afterName": "", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeProperties": "\r\n", + "beforeType": " " + }, + "type": "TEdit" + } + ], + "kind": "object", + "name": "SubForm", + "properties": [], + "raws": { + "afterName": "", + "before": "\r\n", + "beforeChildren": "\r\n", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeType": " " + }, + "type": "TForm2" + }, + { + "astType": "object", + "children": [], + "kind": "object", + "name": "Nothing", + "properties": [], + "raws": { + "afterName": "", + "before": "\r\n", + "beforeEnd": "\r\n", + "beforeName": " ", + "beforeType": " " + }, + "type": "_TNothing" + } + ], + "kind": "object", + "name": "Form1", + "properties": [ + { + "astType": "property", + "name": "Left", + "raws": { + "afterName": " ", + "beforeValue": "\r\n\r\n\r\n\r\n " + }, + "value": { + "astType": "integer", + "value": "192" + } + }, + { + "astType": "property", + "name": "Font.Name", + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + }, + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "MS Sans Serif" + } + ] + } + }, + { + "astType": "property", + "name": "Font.Style", + "raws": { + "afterName": " ", + "before": " ", + "beforeValue": " " + }, + "value": { + "astType": "identifierList", + "raws": { + "beforeClose": "" + }, + "values": [] + } + }, + { + "astType": "property", + "name": "Border.Bottom.Style", + "raws": { + "afterName": " ", + "before": " ", + "beforeValue": " " + }, + "value": { + "astType": "identifier", + "value": "bdSolid" + } + } + ], + "raws": { + "afterName": "", + "beforeChildren": " ", + "beforeEnd": "\r\n", + "beforeName": "\r\n\r\n\r\n\r\n ", + "beforeProperties": "\r\n ", + "beforeType": " " + }, + "type": "TForm1" + }, + "raws": { + "after": "\r\n", + "before": "" + } +} diff --git a/__test__/__fixtures__/transform/hello-world/transformer.js b/__test__/__fixtures__/transform/hello-world/transformer.js index 31ccd8f4..51a3ef43 100644 --- a/__test__/__fixtures__/transform/hello-world/transformer.js +++ b/__test__/__fixtures__/transform/hello-world/transformer.js @@ -1,7 +1,7 @@ function gatherObjects(object) { return [].concat( object, - object.children.map(child => gatherObjects(child)) + object.children.map((child) => gatherObjects(child)) ); } @@ -14,15 +14,12 @@ function gatherProperties(object) { } function visitProperties(object, callback) { - gatherProperties(object).forEach(property => callback(property)); + gatherProperties(object).forEach((property) => callback(property)); } -module.exports = ast => { - visitProperties(ast.child, property => { - property.name = property.name - .split("") - .reverse() - .join(""); +module.exports = (ast) => { + visitProperties(ast.child, (property) => { + property.name = property.name.split("").reverse().join(""); }); return ast; diff --git a/commitlint.config.js b/commitlint.config.js index 207b59fd..69b4242c 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,3 @@ -module.exports = { - extends: ["@commitlint/config-conventional"] -}; +module.exports = { + extends: ["@commitlint/config-conventional"], +}; diff --git a/eslint.config.js b/eslint.config.js index 6779929f..43a5ab0b 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,45 +1,45 @@ -module.exports = function getConfig(enableTypeChecking) { - return { - parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint"], - settings: { - node: { - allowModules: ["@postdfm/ast2dfm", "@postdfm/ast", "@postdfm/dfm2ast"], - tryExtensions: [".js", ".ts", ".json", ".node"] - } - }, - parserOptions: { - project: "./tsconfig.json" - }, - extends: [ - "eslint:recommended", - "plugin:node/recommended", - "plugin:jest/recommended", - "prettier" - ], - overrides: [ - { - files: ["*.ts"], - extends: [ - "eslint:recommended", - "plugin:node/recommended", - "plugin:jest/recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended", - enableTypeChecking && - "plugin:@typescript-eslint/recommended-requiring-type-checking", - "prettier", - "prettier/@typescript-eslint" - ].filter(v => !!v), - rules: { - "node/no-unsupported-features/es-syntax": [ - "error", - { - ignores: ["modules"] - } - ] - } - } - ] - }; -}; +module.exports = function getConfig(enableTypeChecking) { + return { + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint"], + settings: { + node: { + allowModules: ["@postdfm/ast2dfm", "@postdfm/ast", "@postdfm/dfm2ast"], + tryExtensions: [".js", ".ts", ".json", ".node"], + }, + }, + parserOptions: { + project: "./tsconfig.json", + }, + extends: [ + "eslint:recommended", + "plugin:node/recommended", + "plugin:jest/recommended", + "prettier", + ], + overrides: [ + { + files: ["*.ts"], + extends: [ + "eslint:recommended", + "plugin:node/recommended", + "plugin:jest/recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + enableTypeChecking && + "plugin:@typescript-eslint/recommended-requiring-type-checking", + "prettier", + "prettier/@typescript-eslint", + ].filter((v) => !!v), + rules: { + "node/no-unsupported-features/es-syntax": [ + "error", + { + ignores: ["modules"], + }, + ], + }, + }, + ], + }; +}; diff --git a/jest.config.js b/jest.config.js index d3be67fc..2365bf1e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,21 +8,21 @@ module.exports = { classNameTemplate: "[{classname}]", titleTemplate: "{title}", outputDirectory: "test-results/jest", - outputName: "./report.xml" - } - ] + outputName: "./report.xml", + }, + ], ], transform: { - "^.+\\.tsx?$": "ts-jest" + "^.+\\.tsx?$": "ts-jest", }, collectCoverage: true, collectCoverageFrom: [ "**/*.ts", "!**/node_modules/**", "!**/dist/**", - "!packages/@postdfm/dfm2ast/src/grammar.ts" + "!packages/@postdfm/dfm2ast/src/grammar.ts", ], coverageReporters: ["lcov", "text"], coverageDirectory: "coverage", - rootDir: "./" + rootDir: "./", }; diff --git a/packages/@postdfm/ast/.eslintrc.js b/packages/@postdfm/ast/.eslintrc.js index d177fd35..dad6750a 100644 --- a/packages/@postdfm/ast/.eslintrc.js +++ b/packages/@postdfm/ast/.eslintrc.js @@ -1 +1 @@ -module.exports = require("../../../eslint.config.js")(true); +module.exports = require("../../../eslint.config.js")(true); diff --git a/packages/@postdfm/ast/README.md b/packages/@postdfm/ast/README.md index a4e22016..e6943463 100644 --- a/packages/@postdfm/ast/README.md +++ b/packages/@postdfm/ast/README.md @@ -1,12 +1,12 @@ -# @postdfm/ast - -[![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) -[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast/package.json) - -Sub-package for `postdfm`. - -Provides the AST structures used by `postdfm`. - -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast/). +# @postdfm/ast + +[![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast/package.json) + +Sub-package for `postdfm`. + +Provides the AST structures used by `postdfm`. + +See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast/). diff --git a/packages/@postdfm/ast/__test__/item.test.ts b/packages/@postdfm/ast/__test__/item.test.ts index 0ced4da0..3ca1e4c4 100644 --- a/packages/@postdfm/ast/__test__/item.test.ts +++ b/packages/@postdfm/ast/__test__/item.test.ts @@ -1,19 +1,19 @@ -import * as AST from "../src"; - -describe("creating Items", () => { - test("empty Item", () => { - const node = new AST.Item(); - - expect(node.properties).toHaveLength(0); - }); - - test("Item", () => { - const propertyNode = new AST.Property( - "Font.Name", - new AST.StringValue([new AST.LiteralString("sans-serif")]) - ); - const node = new AST.Item([propertyNode]); - - expect(node.properties).toContainEqual(propertyNode); - }); -}); +import * as AST from "../src"; + +describe("creating Items", () => { + test("empty Item", () => { + const node = new AST.Item(); + + expect(node.properties).toHaveLength(0); + }); + + test("Item", () => { + const propertyNode = new AST.Property( + "Font.Name", + new AST.StringValue([new AST.LiteralString("sans-serif")]) + ); + const node = new AST.Item([propertyNode]); + + expect(node.properties).toContainEqual(propertyNode); + }); +}); diff --git a/packages/@postdfm/ast/__test__/list.test.ts b/packages/@postdfm/ast/__test__/list.test.ts index 5720ef8e..05b2e889 100644 --- a/packages/@postdfm/ast/__test__/list.test.ts +++ b/packages/@postdfm/ast/__test__/list.test.ts @@ -1,75 +1,75 @@ -import * as AST from "../src"; - -describe("creating Lists", () => { - test("empty VariantList", () => { - const node = new AST.VariantList(); - - expect(node.values).toHaveLength(0); - }); - - test("VariantList", () => { - const node = new AST.VariantList([ - new AST.StringValue([new AST.LiteralString("hello")]), - new AST.IntegerValue(255), - new AST.BooleanValue(true), - new AST.StringValue([new AST.LiteralString("world")]) - ]); - - expect(node.values).toContainEqual( - new AST.StringValue([new AST.LiteralString("world")]) - ); - - expect(node.values).toContainEqual(new AST.IntegerValue(255)); - - expect(node.values).toContainEqual(new AST.BooleanValue(true)); - }); - - test("empty BinaryStringList", () => { - const node = new AST.BinaryStringList(); - - expect(node.values).toHaveLength(0); - }); - - test("BinaryStringList", () => { - const node = new AST.BinaryStringList([ - new AST.BinaryStringValue("BADA55"), - new AST.BinaryStringValue("C0FFEE") - ]); - - expect(node.values).toContainEqual(new AST.BinaryStringValue("C0FFEE")); - }); - - test("empty QualifiedList", () => { - const node = new AST.IdentifierList(); - - expect(node.values).toHaveLength(0); - }); - - test("QualifiedList", () => { - const node = new AST.IdentifierList([ - new AST.IdentifierValue("enHello"), - new AST.IdentifierValue("enWorld") - ]); - - expect(node.values).toContainEqual(new AST.IdentifierValue("enWorld")); - }); - - test("empty ItemList", () => { - const node = new AST.ItemList(); - - expect(node.values).toHaveLength(0); - }); - - test("ItemList", () => { - const itemNode1 = new AST.Item(); - const itemNode2 = new AST.Item([ - new AST.Property( - "Font.Name", - new AST.StringValue([new AST.LiteralString("sans-serif")]) - ) - ]); - const node = new AST.ItemList([itemNode1, itemNode2]); - - expect(node.values).toContainEqual(itemNode2); - }); -}); +import * as AST from "../src"; + +describe("creating Lists", () => { + test("empty VariantList", () => { + const node = new AST.VariantList(); + + expect(node.values).toHaveLength(0); + }); + + test("VariantList", () => { + const node = new AST.VariantList([ + new AST.StringValue([new AST.LiteralString("hello")]), + new AST.IntegerValue(255), + new AST.BooleanValue(true), + new AST.StringValue([new AST.LiteralString("world")]), + ]); + + expect(node.values).toContainEqual( + new AST.StringValue([new AST.LiteralString("world")]) + ); + + expect(node.values).toContainEqual(new AST.IntegerValue(255)); + + expect(node.values).toContainEqual(new AST.BooleanValue(true)); + }); + + test("empty BinaryStringList", () => { + const node = new AST.BinaryStringList(); + + expect(node.values).toHaveLength(0); + }); + + test("BinaryStringList", () => { + const node = new AST.BinaryStringList([ + new AST.BinaryStringValue("BADA55"), + new AST.BinaryStringValue("C0FFEE"), + ]); + + expect(node.values).toContainEqual(new AST.BinaryStringValue("C0FFEE")); + }); + + test("empty QualifiedList", () => { + const node = new AST.IdentifierList(); + + expect(node.values).toHaveLength(0); + }); + + test("QualifiedList", () => { + const node = new AST.IdentifierList([ + new AST.IdentifierValue("enHello"), + new AST.IdentifierValue("enWorld"), + ]); + + expect(node.values).toContainEqual(new AST.IdentifierValue("enWorld")); + }); + + test("empty ItemList", () => { + const node = new AST.ItemList(); + + expect(node.values).toHaveLength(0); + }); + + test("ItemList", () => { + const itemNode1 = new AST.Item(); + const itemNode2 = new AST.Item([ + new AST.Property( + "Font.Name", + new AST.StringValue([new AST.LiteralString("sans-serif")]) + ), + ]); + const node = new AST.ItemList([itemNode1, itemNode2]); + + expect(node.values).toContainEqual(itemNode2); + }); +}); diff --git a/packages/@postdfm/ast/__test__/property.test.ts b/packages/@postdfm/ast/__test__/property.test.ts index ee454c09..a9140227 100644 --- a/packages/@postdfm/ast/__test__/property.test.ts +++ b/packages/@postdfm/ast/__test__/property.test.ts @@ -1,24 +1,24 @@ -import * as AST from "../src"; - -describe("creating Properties", () => { - test("Property with Value", () => { - const valueNode = new AST.StringValue([ - new AST.LiteralString("sans-serif") - ]); - const node = new AST.Property("Font.Name", valueNode); - - expect(node.name).toBe("Font.Name"); - expect(node.value).toEqual(valueNode); - }); - - test("Property with List", () => { - const listNode = new AST.VariantList([ - new AST.StringValue([new AST.LiteralString("Verdana")]), - new AST.StringValue([new AST.LiteralString("sans-serif")]) - ]); - const node = new AST.Property("Font.Name", listNode); - - expect(node.name).toBe("Font.Name"); - expect(node.value).toEqual(listNode); - }); -}); +import * as AST from "../src"; + +describe("creating Properties", () => { + test("Property with Value", () => { + const valueNode = new AST.StringValue([ + new AST.LiteralString("sans-serif"), + ]); + const node = new AST.Property("Font.Name", valueNode); + + expect(node.name).toBe("Font.Name"); + expect(node.value).toEqual(valueNode); + }); + + test("Property with List", () => { + const listNode = new AST.VariantList([ + new AST.StringValue([new AST.LiteralString("Verdana")]), + new AST.StringValue([new AST.LiteralString("sans-serif")]), + ]); + const node = new AST.Property("Font.Name", listNode); + + expect(node.name).toBe("Font.Name"); + expect(node.value).toEqual(listNode); + }); +}); diff --git a/packages/@postdfm/ast/__test__/value.test.ts b/packages/@postdfm/ast/__test__/value.test.ts index 5335bab0..d8e23fe3 100644 --- a/packages/@postdfm/ast/__test__/value.test.ts +++ b/packages/@postdfm/ast/__test__/value.test.ts @@ -1,157 +1,157 @@ -import * as AST from "../src"; - -describe("creating Values", () => { - test("empty ControlString", () => { - const node = new AST.ControlString(); - expect(node.value).toEqual(""); - }); - - test("ControlString", () => { - const node = new AST.ControlString(); - expect(node.value).toEqual(""); - }); - - test("empty LiteralString", () => { - const node = new AST.LiteralString(); - expect(node.value).toEqual(""); - }); - - test("LiteralString", () => { - const node = new AST.LiteralString(); - expect(node.value).toEqual(""); - }); - - test("empty StringValue", () => { - const node = new AST.StringValue(); - expect(node.value).toEqual([]); - }); - - test("StringValue", () => { - const node = new AST.StringValue([ - new AST.LiteralString("hello"), - new AST.ControlString("\r\n"), - new AST.LiteralString("world") - ]); - expect(node.value).toContainEqual(new AST.LiteralString("world")); - }); - - test("empty BinaryStringValue", () => { - const node = new AST.BinaryStringValue(); - expect(node.value).toBe(""); - }); - - test("BinaryStringValue", () => { - const node = new AST.BinaryStringValue("FFFFFFFF"); - expect(node.value).toBe("FFFFFFFF"); - }); - - test("empty HexCodeValue", () => { - const node = new AST.HexCodeValue(); - expect(node.value).toBe(""); - }); - - test("HexCodeValue", () => { - const node = new AST.HexCodeValue("FFFFFFFF"); - expect(node.value).toBe("FFFFFFFF"); - }); - - test("empty IntegerValue", () => { - const node = new AST.IntegerValue(); - expect(node.value).toBe(0); - }); - - test("IntegerValue", () => { - const node = new AST.IntegerValue(1337); - expect(node.value).toBe(1337); - }); - - test("empty DoubleValue", () => { - const node = new AST.DoubleValue(); - - expect(node.value).toEqual({ integer: "0" }); - }); - - test("DoubleValue", () => { - const node = new AST.DoubleValue({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - - expect(node.value).toEqual({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - }); - - test("empty SingleValue", () => { - const node = new AST.SingleValue(); - - expect(node.value).toEqual({ integer: "0" }); - }); - - test("SingleValue", () => { - const node = new AST.SingleValue({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - - expect(node.value).toEqual({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - }); - - test("empty CurrencyValue", () => { - const node = new AST.CurrencyValue(); - - expect(node.value).toEqual({ integer: "0" }); - }); - - test("CurrencyValue", () => { - const node = new AST.CurrencyValue({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - - expect(node.value).toEqual({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - }); - - test("empty DateTimeValue", () => { - const node = new AST.DateTimeValue(); - - expect(node.value).toEqual({ integer: "0" }); - }); - - test("DateTimeValue", () => { - const node = new AST.DateTimeValue({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - - expect(node.value).toEqual({ - exponent: "1337", - fraction: "000069", - integer: "420" - }); - }); - - test("BooleanValue", () => { - const node = new AST.BooleanValue(true); - expect(node.value).toBe(true); - }); - - test("IdentifierValue", () => { - const node = new AST.IdentifierValue("neIdentifier"); - expect(node.value).toBe("neIdentifier"); - }); -}); +import * as AST from "../src"; + +describe("creating Values", () => { + test("empty ControlString", () => { + const node = new AST.ControlString(); + expect(node.value).toEqual(""); + }); + + test("ControlString", () => { + const node = new AST.ControlString(); + expect(node.value).toEqual(""); + }); + + test("empty LiteralString", () => { + const node = new AST.LiteralString(); + expect(node.value).toEqual(""); + }); + + test("LiteralString", () => { + const node = new AST.LiteralString(); + expect(node.value).toEqual(""); + }); + + test("empty StringValue", () => { + const node = new AST.StringValue(); + expect(node.value).toEqual([]); + }); + + test("StringValue", () => { + const node = new AST.StringValue([ + new AST.LiteralString("hello"), + new AST.ControlString("\r\n"), + new AST.LiteralString("world"), + ]); + expect(node.value).toContainEqual(new AST.LiteralString("world")); + }); + + test("empty BinaryStringValue", () => { + const node = new AST.BinaryStringValue(); + expect(node.value).toBe(""); + }); + + test("BinaryStringValue", () => { + const node = new AST.BinaryStringValue("FFFFFFFF"); + expect(node.value).toBe("FFFFFFFF"); + }); + + test("empty HexCodeValue", () => { + const node = new AST.HexCodeValue(); + expect(node.value).toBe(""); + }); + + test("HexCodeValue", () => { + const node = new AST.HexCodeValue("FFFFFFFF"); + expect(node.value).toBe("FFFFFFFF"); + }); + + test("empty IntegerValue", () => { + const node = new AST.IntegerValue(); + expect(node.value).toBe(0); + }); + + test("IntegerValue", () => { + const node = new AST.IntegerValue(1337); + expect(node.value).toBe(1337); + }); + + test("empty DoubleValue", () => { + const node = new AST.DoubleValue(); + + expect(node.value).toEqual({ integer: "0" }); + }); + + test("DoubleValue", () => { + const node = new AST.DoubleValue({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + + expect(node.value).toEqual({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + }); + + test("empty SingleValue", () => { + const node = new AST.SingleValue(); + + expect(node.value).toEqual({ integer: "0" }); + }); + + test("SingleValue", () => { + const node = new AST.SingleValue({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + + expect(node.value).toEqual({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + }); + + test("empty CurrencyValue", () => { + const node = new AST.CurrencyValue(); + + expect(node.value).toEqual({ integer: "0" }); + }); + + test("CurrencyValue", () => { + const node = new AST.CurrencyValue({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + + expect(node.value).toEqual({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + }); + + test("empty DateTimeValue", () => { + const node = new AST.DateTimeValue(); + + expect(node.value).toEqual({ integer: "0" }); + }); + + test("DateTimeValue", () => { + const node = new AST.DateTimeValue({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + + expect(node.value).toEqual({ + exponent: "1337", + fraction: "000069", + integer: "420", + }); + }); + + test("BooleanValue", () => { + const node = new AST.BooleanValue(true); + expect(node.value).toBe(true); + }); + + test("IdentifierValue", () => { + const node = new AST.IdentifierValue("neIdentifier"); + expect(node.value).toBe("neIdentifier"); + }); +}); diff --git a/packages/@postdfm/ast/src/astNode.ts b/packages/@postdfm/ast/src/astNode.ts index 0db085d4..5f05f448 100644 --- a/packages/@postdfm/ast/src/astNode.ts +++ b/packages/@postdfm/ast/src/astNode.ts @@ -1,11 +1,11 @@ -import { ASTType } from "./astType"; -import { ASTRaws } from "./astRaws"; - -export class ASTNode { - public astType: ASTType; - - public raws: R; - constructor(astType: ASTType) { - this.astType = astType; - } -} +import { ASTType } from "./astType"; +import { ASTRaws } from "./astRaws"; + +export class ASTNode { + public astType: ASTType; + + public raws: R; + constructor(astType: ASTType) { + this.astType = astType; + } +} diff --git a/packages/@postdfm/ast/src/astRaws.ts b/packages/@postdfm/ast/src/astRaws.ts index 167c8dc4..bee04aa8 100644 --- a/packages/@postdfm/ast/src/astRaws.ts +++ b/packages/@postdfm/ast/src/astRaws.ts @@ -1,4 +1,4 @@ -export interface ASTRaws { - before?: string; - after?: string; -} +export interface ASTRaws { + before?: string; + after?: string; +} diff --git a/packages/@postdfm/ast/src/astType.ts b/packages/@postdfm/ast/src/astType.ts index 9f423bbd..68e403e7 100644 --- a/packages/@postdfm/ast/src/astType.ts +++ b/packages/@postdfm/ast/src/astType.ts @@ -1,22 +1,22 @@ -export enum ASTType { - String = "string", - ControlString = "controlString", - LiteralString = "literalString", - BinaryString = "binaryString", - Integer = "integer", - HexCode = "hexCode", - Double = "double", - Single = "single", - Currency = "currency", - DateTime = "dateTime", - Boolean = "boolean", - Identifier = "identifier", - Item = "item", - VariantList = "variantList", - BinaryStringList = "binaryStringList", - IdentifierList = "identifierList", - ItemList = "itemList", - Property = "property", - Object = "object", - Root = "root" -} +export enum ASTType { + String = "string", + ControlString = "controlString", + LiteralString = "literalString", + BinaryString = "binaryString", + Integer = "integer", + HexCode = "hexCode", + Double = "double", + Single = "single", + Currency = "currency", + DateTime = "dateTime", + Boolean = "boolean", + Identifier = "identifier", + Item = "item", + VariantList = "variantList", + BinaryStringList = "binaryStringList", + IdentifierList = "identifierList", + ItemList = "itemList", + Property = "property", + Object = "object", + Root = "root", +} diff --git a/packages/@postdfm/ast/src/index.ts b/packages/@postdfm/ast/src/index.ts index e8d2843f..0f36b0bc 100644 --- a/packages/@postdfm/ast/src/index.ts +++ b/packages/@postdfm/ast/src/index.ts @@ -1,35 +1,35 @@ -export { ASTType } from "./astType"; -export { ASTRaws } from "./astRaws"; -export { ASTNode } from "./astNode"; - -export { Keywords } from "./keywords"; - -export { Value } from "./value/value"; -export { StringValue } from "./value/stringValue"; -export { ControlString } from "./value/controlString"; -export { LiteralString } from "./value/literalString"; -export { BinaryStringValue } from "./value/binaryStringValue"; -export { IntegerValue } from "./value/integerValue"; -export { HexCodeValue } from "./value/hexCodeValue"; -export { DoubleValue } from "./value/doubleValue"; -export { SingleValue } from "./value/singleValue"; -export { CurrencyValue } from "./value/currencyValue"; -export { DateTimeValue } from "./value/dateTimeValue"; -export { BooleanValue } from "./value/booleanValue"; -export { IdentifierValue } from "./value/identifierValue"; - -export { Item } from "./item"; - -export { List } from "./list/list"; -export { BinaryStringList } from "./list/binaryStringList"; -export { IdentifierList } from "./list/identifierList"; -export { VariantList } from "./list/variantList"; -export { ItemList } from "./list/itemList"; - -export { Property } from "./property"; - -export { ObjectKind } from "./objectKind"; - -export { DObject } from "./object"; - -export { Root } from "./root"; +export { ASTType } from "./astType"; +export { ASTRaws } from "./astRaws"; +export { ASTNode } from "./astNode"; + +export { Keywords } from "./keywords"; + +export { Value } from "./value/value"; +export { StringValue } from "./value/stringValue"; +export { ControlString } from "./value/controlString"; +export { LiteralString } from "./value/literalString"; +export { BinaryStringValue } from "./value/binaryStringValue"; +export { IntegerValue } from "./value/integerValue"; +export { HexCodeValue } from "./value/hexCodeValue"; +export { DoubleValue } from "./value/doubleValue"; +export { SingleValue } from "./value/singleValue"; +export { CurrencyValue } from "./value/currencyValue"; +export { DateTimeValue } from "./value/dateTimeValue"; +export { BooleanValue } from "./value/booleanValue"; +export { IdentifierValue } from "./value/identifierValue"; + +export { Item } from "./item"; + +export { List } from "./list/list"; +export { BinaryStringList } from "./list/binaryStringList"; +export { IdentifierList } from "./list/identifierList"; +export { VariantList } from "./list/variantList"; +export { ItemList } from "./list/itemList"; + +export { Property } from "./property"; + +export { ObjectKind } from "./objectKind"; + +export { DObject } from "./object"; + +export { Root } from "./root"; diff --git a/packages/@postdfm/ast/src/item.ts b/packages/@postdfm/ast/src/item.ts index b59f7b00..904b8f73 100644 --- a/packages/@postdfm/ast/src/item.ts +++ b/packages/@postdfm/ast/src/item.ts @@ -1,18 +1,18 @@ -import { ASTNode } from "./astNode"; -import { ASTRaws } from "./astRaws"; -import { ASTType } from "./astType"; -import { Property } from "./property"; - -interface ItemRaws extends ASTRaws { - afterItem?: string; - beforeEnd?: string; -} - -export class Item extends ASTNode { - public properties: Property[]; - - constructor(properties?: Property[]) { - super(ASTType.Item); - this.properties = properties || []; - } -} +import { ASTNode } from "./astNode"; +import { ASTRaws } from "./astRaws"; +import { ASTType } from "./astType"; +import { Property } from "./property"; + +interface ItemRaws extends ASTRaws { + afterItem?: string; + beforeEnd?: string; +} + +export class Item extends ASTNode { + public properties: Property[]; + + constructor(properties?: Property[]) { + super(ASTType.Item); + this.properties = properties || []; + } +} diff --git a/packages/@postdfm/ast/src/keywords.ts b/packages/@postdfm/ast/src/keywords.ts index 01b48408..292cfd07 100644 --- a/packages/@postdfm/ast/src/keywords.ts +++ b/packages/@postdfm/ast/src/keywords.ts @@ -5,5 +5,5 @@ export const Keywords = [ "inherited", "inline", "end", - "item" + "item", ]; diff --git a/packages/@postdfm/ast/src/list/binaryStringList.ts b/packages/@postdfm/ast/src/list/binaryStringList.ts index 75b8c284..4f0f900b 100644 --- a/packages/@postdfm/ast/src/list/binaryStringList.ts +++ b/packages/@postdfm/ast/src/list/binaryStringList.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { BinaryStringValue } from "../value/binaryStringValue"; -import { List } from "./list"; - -export class BinaryStringList extends List { - constructor(values?: BinaryStringValue[]) { - super(ASTType.BinaryStringList, values || []); - } -} +import { ASTType } from "../astType"; +import { BinaryStringValue } from "../value/binaryStringValue"; +import { List } from "./list"; + +export class BinaryStringList extends List { + constructor(values?: BinaryStringValue[]) { + super(ASTType.BinaryStringList, values || []); + } +} diff --git a/packages/@postdfm/ast/src/list/identifierList.ts b/packages/@postdfm/ast/src/list/identifierList.ts index 7ef930ec..63ca14b0 100644 --- a/packages/@postdfm/ast/src/list/identifierList.ts +++ b/packages/@postdfm/ast/src/list/identifierList.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { IdentifierValue } from "../value/identifierValue"; -import { List } from "./list"; - -export class IdentifierList extends List { - constructor(values?: IdentifierValue[]) { - super(ASTType.IdentifierList, values || []); - } -} +import { ASTType } from "../astType"; +import { IdentifierValue } from "../value/identifierValue"; +import { List } from "./list"; + +export class IdentifierList extends List { + constructor(values?: IdentifierValue[]) { + super(ASTType.IdentifierList, values || []); + } +} diff --git a/packages/@postdfm/ast/src/list/itemList.ts b/packages/@postdfm/ast/src/list/itemList.ts index 586c2ea9..3d7bd8d8 100644 --- a/packages/@postdfm/ast/src/list/itemList.ts +++ b/packages/@postdfm/ast/src/list/itemList.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { Item } from "../item"; -import { List } from "./list"; - -export class ItemList extends List { - constructor(values?: Item[]) { - super(ASTType.ItemList, values || []); - } -} +import { ASTType } from "../astType"; +import { Item } from "../item"; +import { List } from "./list"; + +export class ItemList extends List { + constructor(values?: Item[]) { + super(ASTType.ItemList, values || []); + } +} diff --git a/packages/@postdfm/ast/src/list/list.ts b/packages/@postdfm/ast/src/list/list.ts index ef830a50..3664a995 100644 --- a/packages/@postdfm/ast/src/list/list.ts +++ b/packages/@postdfm/ast/src/list/list.ts @@ -1,16 +1,16 @@ -import { ASTNode } from "../astNode"; -import { ASTRaws } from "../astRaws"; -import { ASTType } from "../astType"; - -interface ListRaws extends ASTRaws { - afterOpen?: string; - beforeClose?: string; -} -export class List extends ASTNode { - public values: T[]; - - constructor(astType: ASTType, values: T[]) { - super(astType); - this.values = values; - } -} +import { ASTNode } from "../astNode"; +import { ASTRaws } from "../astRaws"; +import { ASTType } from "../astType"; + +interface ListRaws extends ASTRaws { + afterOpen?: string; + beforeClose?: string; +} +export class List extends ASTNode { + public values: T[]; + + constructor(astType: ASTType, values: T[]) { + super(astType); + this.values = values; + } +} diff --git a/packages/@postdfm/ast/src/list/variantList.ts b/packages/@postdfm/ast/src/list/variantList.ts index b9c00a74..b717e31e 100644 --- a/packages/@postdfm/ast/src/list/variantList.ts +++ b/packages/@postdfm/ast/src/list/variantList.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { VariantValue } from "../value/variantValue"; -import { List } from "./list"; - -export class VariantList extends List { - constructor(values?: Array) { - super(ASTType.VariantList, values || []); - } -} +import { ASTType } from "../astType"; +import { VariantValue } from "../value/variantValue"; +import { List } from "./list"; + +export class VariantList extends List { + constructor(values?: Array) { + super(ASTType.VariantList, values || []); + } +} diff --git a/packages/@postdfm/ast/src/objectKind.ts b/packages/@postdfm/ast/src/objectKind.ts index 2b8be5be..c0bfb403 100644 --- a/packages/@postdfm/ast/src/objectKind.ts +++ b/packages/@postdfm/ast/src/objectKind.ts @@ -1,5 +1,5 @@ -export enum ObjectKind { - Object = "object", - Inline = "inline", - Inherited = "inherited" -} +export enum ObjectKind { + Object = "object", + Inline = "inline", + Inherited = "inherited", +} diff --git a/packages/@postdfm/ast/src/property.ts b/packages/@postdfm/ast/src/property.ts index e1397b70..1133bfa4 100644 --- a/packages/@postdfm/ast/src/property.ts +++ b/packages/@postdfm/ast/src/property.ts @@ -1,20 +1,20 @@ -import { ASTNode } from "./astNode"; -import { ASTRaws } from "./astRaws"; -import { ASTType } from "./astType"; -import { AnyList } from "./list/anyList"; -import { VariantValue } from "./value/variantValue"; - -interface PropertyRaws extends ASTRaws { - afterName?: string; - beforeValue?: string; -} -export class Property extends ASTNode { - public name: string; - public value: VariantValue | AnyList; - - constructor(name: string, value: VariantValue | AnyList) { - super(ASTType.Property); - this.name = name; - this.value = value; - } -} +import { ASTNode } from "./astNode"; +import { ASTRaws } from "./astRaws"; +import { ASTType } from "./astType"; +import { AnyList } from "./list/anyList"; +import { VariantValue } from "./value/variantValue"; + +interface PropertyRaws extends ASTRaws { + afterName?: string; + beforeValue?: string; +} +export class Property extends ASTNode { + public name: string; + public value: VariantValue | AnyList; + + constructor(name: string, value: VariantValue | AnyList) { + super(ASTType.Property); + this.name = name; + this.value = value; + } +} diff --git a/packages/@postdfm/ast/src/value/binaryStringValue.ts b/packages/@postdfm/ast/src/value/binaryStringValue.ts index a8c09521..44c1ae4a 100644 --- a/packages/@postdfm/ast/src/value/binaryStringValue.ts +++ b/packages/@postdfm/ast/src/value/binaryStringValue.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class BinaryStringValue extends Value { - constructor(value?: string) { - super(ASTType.BinaryString, value || ""); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class BinaryStringValue extends Value { + constructor(value?: string) { + super(ASTType.BinaryString, value || ""); + } +} diff --git a/packages/@postdfm/ast/src/value/booleanValue.ts b/packages/@postdfm/ast/src/value/booleanValue.ts index ef352d44..a65b8dc3 100644 --- a/packages/@postdfm/ast/src/value/booleanValue.ts +++ b/packages/@postdfm/ast/src/value/booleanValue.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class BooleanValue extends Value { - constructor(value: boolean) { - super(ASTType.Boolean, value); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class BooleanValue extends Value { + constructor(value: boolean) { + super(ASTType.Boolean, value); + } +} diff --git a/packages/@postdfm/ast/src/value/controlString.ts b/packages/@postdfm/ast/src/value/controlString.ts index e2a9f196..3afdef68 100644 --- a/packages/@postdfm/ast/src/value/controlString.ts +++ b/packages/@postdfm/ast/src/value/controlString.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { StringValuePart } from "./stringValuePart"; - -export class ControlString extends StringValuePart { - constructor(value?: string) { - super(ASTType.ControlString, value); - } -} +import { ASTType } from "../astType"; +import { StringValuePart } from "./stringValuePart"; + +export class ControlString extends StringValuePart { + constructor(value?: string) { + super(ASTType.ControlString, value); + } +} diff --git a/packages/@postdfm/ast/src/value/currencyValue.ts b/packages/@postdfm/ast/src/value/currencyValue.ts index 05083aac..fc6fac98 100644 --- a/packages/@postdfm/ast/src/value/currencyValue.ts +++ b/packages/@postdfm/ast/src/value/currencyValue.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { Float } from "./float"; -import { Value } from "./value"; - -export class CurrencyValue extends Value { - constructor(value?: Float) { - super(ASTType.Currency, value || { integer: "0" }); - } -} +import { ASTType } from "../astType"; +import { Float } from "./float"; +import { Value } from "./value"; + +export class CurrencyValue extends Value { + constructor(value?: Float) { + super(ASTType.Currency, value || { integer: "0" }); + } +} diff --git a/packages/@postdfm/ast/src/value/dateTimeValue.ts b/packages/@postdfm/ast/src/value/dateTimeValue.ts index 1add4f62..53db6fed 100644 --- a/packages/@postdfm/ast/src/value/dateTimeValue.ts +++ b/packages/@postdfm/ast/src/value/dateTimeValue.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { Float } from "./float"; -import { Value } from "./value"; - -export class DateTimeValue extends Value { - constructor(value?: Float) { - super(ASTType.DateTime, value || { integer: "0" }); - } -} +import { ASTType } from "../astType"; +import { Float } from "./float"; +import { Value } from "./value"; + +export class DateTimeValue extends Value { + constructor(value?: Float) { + super(ASTType.DateTime, value || { integer: "0" }); + } +} diff --git a/packages/@postdfm/ast/src/value/doubleValue.ts b/packages/@postdfm/ast/src/value/doubleValue.ts index 3ea00d83..d039f331 100644 --- a/packages/@postdfm/ast/src/value/doubleValue.ts +++ b/packages/@postdfm/ast/src/value/doubleValue.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { Float } from "./float"; -import { Value } from "./value"; - -export class DoubleValue extends Value { - constructor(value?: Float) { - super(ASTType.Double, value || { integer: "0" }); - } -} +import { ASTType } from "../astType"; +import { Float } from "./float"; +import { Value } from "./value"; + +export class DoubleValue extends Value { + constructor(value?: Float) { + super(ASTType.Double, value || { integer: "0" }); + } +} diff --git a/packages/@postdfm/ast/src/value/float.ts b/packages/@postdfm/ast/src/value/float.ts index 126fcd17..ff7d5fb0 100644 --- a/packages/@postdfm/ast/src/value/float.ts +++ b/packages/@postdfm/ast/src/value/float.ts @@ -1,5 +1,5 @@ -export interface Float { - integer: string; - fraction?: string; - exponent?: string; -} +export interface Float { + integer: string; + fraction?: string; + exponent?: string; +} diff --git a/packages/@postdfm/ast/src/value/hexCodeValue.ts b/packages/@postdfm/ast/src/value/hexCodeValue.ts index 955ae6f8..c6dd504c 100644 --- a/packages/@postdfm/ast/src/value/hexCodeValue.ts +++ b/packages/@postdfm/ast/src/value/hexCodeValue.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class HexCodeValue extends Value { - constructor(value?: string) { - super(ASTType.HexCode, value || ""); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class HexCodeValue extends Value { + constructor(value?: string) { + super(ASTType.HexCode, value || ""); + } +} diff --git a/packages/@postdfm/ast/src/value/identifierValue.ts b/packages/@postdfm/ast/src/value/identifierValue.ts index 90cbd4f6..b71db9df 100644 --- a/packages/@postdfm/ast/src/value/identifierValue.ts +++ b/packages/@postdfm/ast/src/value/identifierValue.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class IdentifierValue extends Value { - constructor(value: string) { - super(ASTType.Identifier, value); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class IdentifierValue extends Value { + constructor(value: string) { + super(ASTType.Identifier, value); + } +} diff --git a/packages/@postdfm/ast/src/value/integerValue.ts b/packages/@postdfm/ast/src/value/integerValue.ts index 4a42703c..c62ce85a 100644 --- a/packages/@postdfm/ast/src/value/integerValue.ts +++ b/packages/@postdfm/ast/src/value/integerValue.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class IntegerValue extends Value { - constructor(value?: number) { - super(ASTType.Integer, value || 0); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class IntegerValue extends Value { + constructor(value?: number) { + super(ASTType.Integer, value || 0); + } +} diff --git a/packages/@postdfm/ast/src/value/literalString.ts b/packages/@postdfm/ast/src/value/literalString.ts index c9888c21..bee3e121 100644 --- a/packages/@postdfm/ast/src/value/literalString.ts +++ b/packages/@postdfm/ast/src/value/literalString.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { StringValuePart } from "./stringValuePart"; - -export class LiteralString extends StringValuePart { - constructor(value?: string) { - super(ASTType.LiteralString, value); - } -} +import { ASTType } from "../astType"; +import { StringValuePart } from "./stringValuePart"; + +export class LiteralString extends StringValuePart { + constructor(value?: string) { + super(ASTType.LiteralString, value); + } +} diff --git a/packages/@postdfm/ast/src/value/singleValue.ts b/packages/@postdfm/ast/src/value/singleValue.ts index 0054e85d..474cca1a 100644 --- a/packages/@postdfm/ast/src/value/singleValue.ts +++ b/packages/@postdfm/ast/src/value/singleValue.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { Float } from "./float"; -import { Value } from "./value"; - -export class SingleValue extends Value { - constructor(value?: Float) { - super(ASTType.Single, value || { integer: "0" }); - } -} +import { ASTType } from "../astType"; +import { Float } from "./float"; +import { Value } from "./value"; + +export class SingleValue extends Value { + constructor(value?: Float) { + super(ASTType.Single, value || { integer: "0" }); + } +} diff --git a/packages/@postdfm/ast/src/value/stringValue.ts b/packages/@postdfm/ast/src/value/stringValue.ts index 506d2775..1408c48e 100644 --- a/packages/@postdfm/ast/src/value/stringValue.ts +++ b/packages/@postdfm/ast/src/value/stringValue.ts @@ -1,9 +1,9 @@ -import { ASTType } from "../astType"; -import { StringValuePart } from "./stringValuePart"; -import { Value } from "./value"; - -export class StringValue extends Value { - constructor(value?: StringValuePart[]) { - super(ASTType.String, value || []); - } -} +import { ASTType } from "../astType"; +import { StringValuePart } from "./stringValuePart"; +import { Value } from "./value"; + +export class StringValue extends Value { + constructor(value?: StringValuePart[]) { + super(ASTType.String, value || []); + } +} diff --git a/packages/@postdfm/ast/src/value/stringValuePart.ts b/packages/@postdfm/ast/src/value/stringValuePart.ts index 99d9b8b0..5533d97c 100644 --- a/packages/@postdfm/ast/src/value/stringValuePart.ts +++ b/packages/@postdfm/ast/src/value/stringValuePart.ts @@ -1,8 +1,8 @@ -import { ASTType } from "../astType"; -import { Value } from "./value"; - -export class StringValuePart extends Value { - constructor(astType: ASTType, value?: string) { - super(astType, value || ""); - } -} +import { ASTType } from "../astType"; +import { Value } from "./value"; + +export class StringValuePart extends Value { + constructor(astType: ASTType, value?: string) { + super(astType, value || ""); + } +} diff --git a/packages/@postdfm/ast/src/value/value.ts b/packages/@postdfm/ast/src/value/value.ts index 7171d4b8..e8138a03 100644 --- a/packages/@postdfm/ast/src/value/value.ts +++ b/packages/@postdfm/ast/src/value/value.ts @@ -1,10 +1,10 @@ -import { ASTNode } from "../astNode"; -import { ASTType } from "../astType"; - -export class Value extends ASTNode { - public value: T; - constructor(astType: ASTType, value: T) { - super(astType); - this.value = value; - } -} +import { ASTNode } from "../astNode"; +import { ASTType } from "../astType"; + +export class Value extends ASTNode { + public value: T; + constructor(astType: ASTType, value: T) { + super(astType); + this.value = value; + } +} diff --git a/packages/@postdfm/ast/typedoc.config.js b/packages/@postdfm/ast/typedoc.config.js index 704916c7..e5786030 100644 --- a/packages/@postdfm/ast/typedoc.config.js +++ b/packages/@postdfm/ast/typedoc.config.js @@ -1,3 +1,3 @@ -module.exports = require("../../../typedoc")({ - out: "@postdfm/ast" -}); +module.exports = require("../../../typedoc")({ + out: "@postdfm/ast", +}); diff --git a/packages/@postdfm/ast2dfm/.eslintrc.js b/packages/@postdfm/ast2dfm/.eslintrc.js index d177fd35..dad6750a 100644 --- a/packages/@postdfm/ast2dfm/.eslintrc.js +++ b/packages/@postdfm/ast2dfm/.eslintrc.js @@ -1 +1 @@ -module.exports = require("../../../eslint.config.js")(true); +module.exports = require("../../../eslint.config.js")(true); diff --git a/packages/@postdfm/ast2dfm/README.md b/packages/@postdfm/ast2dfm/README.md index 409f01b0..3ab712eb 100644 --- a/packages/@postdfm/ast2dfm/README.md +++ b/packages/@postdfm/ast2dfm/README.md @@ -1,12 +1,12 @@ -# @postdfm/ast2dfm - -[![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) -[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast2dfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast2dfm/package.json) - -Sub-package for `postdfm`. - -Provides functionality for turning the structure provided by `@postdfm/ast` into a string. - -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast2dfm/). +# @postdfm/ast2dfm + +[![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast2dfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast2dfm/package.json) + +Sub-package for `postdfm`. + +Provides functionality for turning the structure provided by `@postdfm/ast` into a string. + +See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast2dfm/). diff --git a/packages/@postdfm/ast2dfm/__test__/broken/ast.json b/packages/@postdfm/ast2dfm/__test__/broken/ast.json index b7675d72..2e54457c 100644 --- a/packages/@postdfm/ast2dfm/__test__/broken/ast.json +++ b/packages/@postdfm/ast2dfm/__test__/broken/ast.json @@ -1,3 +1,3 @@ -{ - "astType": "unknown" -} +{ + "astType": "unknown" +} diff --git a/packages/@postdfm/ast2dfm/__test__/broken/index.test.ts b/packages/@postdfm/ast2dfm/__test__/broken/index.test.ts index 2bd0275b..ecbc112b 100644 --- a/packages/@postdfm/ast2dfm/__test__/broken/index.test.ts +++ b/packages/@postdfm/ast2dfm/__test__/broken/index.test.ts @@ -1,14 +1,14 @@ -import * as AST from "@postdfm/ast"; -import * as fs from "fs"; -import * as path from "path"; -import stringify from "../../src"; - -describe("dfm2ast", () => { - test("broken AST throws error", () => { - const ast = JSON.parse( - fs.readFileSync(path.join(__dirname, "ast.json"), "utf8") - ) as AST.Root; - - expect(() => stringify(ast)).toThrow("Cannot stringify astType unknown"); - }); -}); +import * as AST from "@postdfm/ast"; +import * as fs from "fs"; +import * as path from "path"; +import stringify from "../../src"; + +describe("dfm2ast", () => { + test("broken AST throws error", () => { + const ast = JSON.parse( + fs.readFileSync(path.join(__dirname, "ast.json"), "utf8") + ) as AST.Root; + + expect(() => stringify(ast)).toThrow("Cannot stringify astType unknown"); + }); +}); diff --git a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts index 3b674977..b6787cfc 100644 --- a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts @@ -1,23 +1,23 @@ -import * as AST from "@postdfm/ast"; -import * as fs from "fs"; -import * as path from "path"; -import stringify from "../../src"; - -const rootFixturesDir = path.join("__test__", "__fixtures__"); -const parseFixturesDir = path.join(rootFixturesDir, "parse"); - -describe("dfm2ast", () => { - describe("fixtures", () => { - const fixtures = fs.readdirSync(parseFixturesDir); - fixtures.forEach(fixture => { - const astFile = path.join(parseFixturesDir, fixture, "ast.json"); - const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); - - test(fixture, () => { - expect( - stringify(JSON.parse(fs.readFileSync(astFile, "utf8")) as AST.Root) - ).toEqual(fs.readFileSync(formFile, "ascii")); - }); - }); - }); -}); +import * as AST from "@postdfm/ast"; +import * as fs from "fs"; +import * as path from "path"; +import stringify from "../../src"; + +const rootFixturesDir = path.join("__test__", "__fixtures__"); +const parseFixturesDir = path.join(rootFixturesDir, "parse"); + +describe("dfm2ast", () => { + describe("fixtures", () => { + const fixtures = fs.readdirSync(parseFixturesDir); + fixtures.forEach((fixture) => { + const astFile = path.join(parseFixturesDir, fixture, "ast.json"); + const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); + + test(fixture, () => { + expect( + stringify(JSON.parse(fs.readFileSync(astFile, "utf8")) as AST.Root) + ).toEqual(fs.readFileSync(formFile, "ascii")); + }); + }); + }); +}); diff --git a/packages/@postdfm/ast2dfm/src/index.ts b/packages/@postdfm/ast2dfm/src/index.ts index c421adf7..b1cd11e8 100644 --- a/packages/@postdfm/ast2dfm/src/index.ts +++ b/packages/@postdfm/ast2dfm/src/index.ts @@ -1,10 +1,10 @@ -import { Root } from "@postdfm/ast"; -import Stringifier from "./stringifier"; - -function stringify(ast: Root): string { - const stringifier = new Stringifier(); - return stringifier.stringify(ast); -} - -export default stringify; -export { stringify }; +import { Root } from "@postdfm/ast"; +import Stringifier from "./stringifier"; + +function stringify(ast: Root): string { + const stringifier = new Stringifier(); + return stringifier.stringify(ast); +} + +export default stringify; +export { stringify }; diff --git a/packages/@postdfm/ast2dfm/src/stringifier.ts b/packages/@postdfm/ast2dfm/src/stringifier.ts index 08afbc67..55d9bc01 100644 --- a/packages/@postdfm/ast2dfm/src/stringifier.ts +++ b/packages/@postdfm/ast2dfm/src/stringifier.ts @@ -1,281 +1,283 @@ -import * as AST from "@postdfm/ast"; - -export default class Stringifier { - public stringify(ast: AST.ASTNode): string { - switch (ast.astType) { - case AST.ASTType.String: - return this.printString(ast as AST.StringValue); - case AST.ASTType.ControlString: - return this.printControlString(ast as AST.ControlString); - case AST.ASTType.LiteralString: - return this.printLiteralString(ast as AST.LiteralString); - case AST.ASTType.Integer: - return this.printInteger(ast as AST.IntegerValue); - case AST.ASTType.HexCode: - return this.printHexCode(ast as AST.HexCodeValue); - case AST.ASTType.Double: - return this.printDouble(ast as AST.DoubleValue); - case AST.ASTType.Single: - return this.printSingle(ast as AST.SingleValue); - case AST.ASTType.Currency: - return this.printCurrency(ast as AST.CurrencyValue); - case AST.ASTType.DateTime: - return this.printDateTime(ast as AST.DateTimeValue); - case AST.ASTType.Boolean: - return this.printBoolean(ast as AST.BooleanValue); - case AST.ASTType.Identifier: - return this.printIdentifier(ast as AST.IdentifierValue); - case AST.ASTType.VariantList: - return this.printVariantList(ast as AST.VariantList); - case AST.ASTType.BinaryStringList: - return this.printBinaryStringList(ast as AST.BinaryStringList); - case AST.ASTType.IdentifierList: - return this.printIdentifierList(ast as AST.IdentifierList); - case AST.ASTType.ItemList: - return this.printItemList(ast as AST.ItemList); - case AST.ASTType.Root: - return this.printRoot(ast as AST.Root); - default: - throw Error(`Cannot stringify astType ${ast.astType}`); - } - } - - private printString(ast: AST.StringValue): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.value.map(str => this.stringify(str)).join(""), - raws.after - ); - } - - private printControlString(ast: AST.ControlString): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "#", - `${ast.value.charCodeAt(0)}`, - raws.after - ); - } - - private printLiteralString(ast: AST.LiteralString): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "'", - ast.value.replace(/'/g, "''"), - "'", - raws.after - ); - } - - private printBinaryString(ast: AST.BinaryStringValue): string { - const raws = this.raws(ast); - return this.print(raws.before, ast.value, raws.after); - } - - private printInteger(ast: AST.IntegerValue): string { - const raws = this.raws(ast); - return this.print(raws.before, `${ast.value}`, raws.after); - } - - private printHexCode(ast: AST.HexCodeValue): string { - const raws = this.raws(ast); - return this.print(raws.before, "$", ast.value, raws.after); - } - - private printDouble(ast: AST.DoubleValue): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.value.integer, - ast.value.fraction ? `.${ast.value.fraction}` : "", - ast.value.exponent ? `e${ast.value.exponent}` : "", - raws.after - ); - } - - private printSingle(ast: AST.SingleValue): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.value.integer, - ast.value.fraction ? `.${ast.value.fraction}` : "", - ast.value.exponent ? `e${ast.value.exponent}` : "", - "s", - raws.after - ); - } - - private printCurrency(ast: AST.CurrencyValue): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.value.integer, - ast.value.fraction ? `.${ast.value.fraction}` : "", - ast.value.exponent ? `e${ast.value.exponent}` : "", - "c", - raws.after - ); - } - - private printDateTime(ast: AST.DateTimeValue): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.value.integer, - ast.value.fraction ? `.${ast.value.fraction}` : "", - ast.value.exponent ? `e${ast.value.exponent}` : "", - "d", - raws.after - ); - } - - private printBoolean(ast: AST.BooleanValue): string { - const raws = this.raws(ast); - return this.print(raws.before, ast.value ? "True" : "False", raws.after); - } - - private printIdentifier(ast: AST.IdentifierValue): string { - const raws = this.raws(ast); - return this.print(raws.before, ast.value, raws.after); - } - - private printItem(ast: AST.Item): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "item", - raws.afterItem, - ast.properties.map(property => this.printProperty(property)).join(""), - raws.beforeEnd, - "end", - raws.after - ); - } - - private printVariantList(ast: AST.VariantList): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "(", - raws.afterOpen, - ast.values.map(variant => this.stringify(variant)).join(""), - raws.beforeClose, - ")", - raws.after - ); - } - - private printBinaryStringList(ast: AST.BinaryStringList): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "{", - raws.afterOpen, - ast.values - .map(binaryString => this.printBinaryString(binaryString)) - .join(""), - raws.beforeClose, - "}", - raws.after - ); - } - - private printIdentifierList(ast: AST.IdentifierList): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "[", - raws.afterOpen, - ast.values.map(identifier => this.printIdentifier(identifier)).join(","), - raws.beforeClose, - "]", - raws.after - ); - } - - private printItemList(ast: AST.ItemList): string { - const raws = this.raws(ast); - return this.print( - raws.before, - "<", - raws.afterOpen, - ast.values.map(item => this.printItem(item)).join(""), - raws.beforeClose, - ">", - raws.after - ); - } - - private printProperty(ast: AST.Property): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.name, - raws.afterName, - "=", - raws.beforeValue, - this.stringify(ast.value), - raws.after - ); - } - - private printObject(ast: AST.DObject): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.kind, - raws.beforeName, - ast.name, - raws.afterName, - ast.type - ? this.print(":", raws.beforeType, ast.type, raws.afterType) - : "", - ast.order !== undefined - ? this.print( - "[", - raws.beforeOrder, - `${ast.order}`, - raws.afterOrder, - "]" - ) - : "", - ast.properties && ast.properties.length - ? this.print( - raws.beforeProperties, - ast.properties - .map(property => this.printProperty(property)) - .join("") - ) - : "", - ast.children && ast.children.length - ? this.print( - raws.beforeChildren, - ast.children.map(child => this.printObject(child)).join("") - ) - : "", - raws.beforeEnd, - "end", - raws.after - ); - } - - private printRoot(ast: AST.Root): string { - const raws = this.raws(ast); - return this.print( - raws.before, - ast.child ? this.printObject(ast.child) : "", - raws.after - ); - } - - private print(...values: (string | undefined)[]): string { - return values.filter(v => !!v).join(""); - } - - private raws(obj: AST.ASTNode): R { - return obj.raws || {}; - } -} +import * as AST from "@postdfm/ast"; + +export default class Stringifier { + public stringify(ast: AST.ASTNode): string { + switch (ast.astType) { + case AST.ASTType.String: + return this.printString(ast as AST.StringValue); + case AST.ASTType.ControlString: + return this.printControlString(ast as AST.ControlString); + case AST.ASTType.LiteralString: + return this.printLiteralString(ast as AST.LiteralString); + case AST.ASTType.Integer: + return this.printInteger(ast as AST.IntegerValue); + case AST.ASTType.HexCode: + return this.printHexCode(ast as AST.HexCodeValue); + case AST.ASTType.Double: + return this.printDouble(ast as AST.DoubleValue); + case AST.ASTType.Single: + return this.printSingle(ast as AST.SingleValue); + case AST.ASTType.Currency: + return this.printCurrency(ast as AST.CurrencyValue); + case AST.ASTType.DateTime: + return this.printDateTime(ast as AST.DateTimeValue); + case AST.ASTType.Boolean: + return this.printBoolean(ast as AST.BooleanValue); + case AST.ASTType.Identifier: + return this.printIdentifier(ast as AST.IdentifierValue); + case AST.ASTType.VariantList: + return this.printVariantList(ast as AST.VariantList); + case AST.ASTType.BinaryStringList: + return this.printBinaryStringList(ast as AST.BinaryStringList); + case AST.ASTType.IdentifierList: + return this.printIdentifierList(ast as AST.IdentifierList); + case AST.ASTType.ItemList: + return this.printItemList(ast as AST.ItemList); + case AST.ASTType.Root: + return this.printRoot(ast as AST.Root); + default: + throw Error(`Cannot stringify astType ${ast.astType}`); + } + } + + private printString(ast: AST.StringValue): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.value.map((str) => this.stringify(str)).join(""), + raws.after + ); + } + + private printControlString(ast: AST.ControlString): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "#", + `${ast.value.charCodeAt(0)}`, + raws.after + ); + } + + private printLiteralString(ast: AST.LiteralString): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "'", + ast.value.replace(/'/g, "''"), + "'", + raws.after + ); + } + + private printBinaryString(ast: AST.BinaryStringValue): string { + const raws = this.raws(ast); + return this.print(raws.before, ast.value, raws.after); + } + + private printInteger(ast: AST.IntegerValue): string { + const raws = this.raws(ast); + return this.print(raws.before, `${ast.value}`, raws.after); + } + + private printHexCode(ast: AST.HexCodeValue): string { + const raws = this.raws(ast); + return this.print(raws.before, "$", ast.value, raws.after); + } + + private printDouble(ast: AST.DoubleValue): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.value.integer, + ast.value.fraction ? `.${ast.value.fraction}` : "", + ast.value.exponent ? `e${ast.value.exponent}` : "", + raws.after + ); + } + + private printSingle(ast: AST.SingleValue): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.value.integer, + ast.value.fraction ? `.${ast.value.fraction}` : "", + ast.value.exponent ? `e${ast.value.exponent}` : "", + "s", + raws.after + ); + } + + private printCurrency(ast: AST.CurrencyValue): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.value.integer, + ast.value.fraction ? `.${ast.value.fraction}` : "", + ast.value.exponent ? `e${ast.value.exponent}` : "", + "c", + raws.after + ); + } + + private printDateTime(ast: AST.DateTimeValue): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.value.integer, + ast.value.fraction ? `.${ast.value.fraction}` : "", + ast.value.exponent ? `e${ast.value.exponent}` : "", + "d", + raws.after + ); + } + + private printBoolean(ast: AST.BooleanValue): string { + const raws = this.raws(ast); + return this.print(raws.before, ast.value ? "True" : "False", raws.after); + } + + private printIdentifier(ast: AST.IdentifierValue): string { + const raws = this.raws(ast); + return this.print(raws.before, ast.value, raws.after); + } + + private printItem(ast: AST.Item): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "item", + raws.afterItem, + ast.properties.map((property) => this.printProperty(property)).join(""), + raws.beforeEnd, + "end", + raws.after + ); + } + + private printVariantList(ast: AST.VariantList): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "(", + raws.afterOpen, + ast.values.map((variant) => this.stringify(variant)).join(""), + raws.beforeClose, + ")", + raws.after + ); + } + + private printBinaryStringList(ast: AST.BinaryStringList): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "{", + raws.afterOpen, + ast.values + .map((binaryString) => this.printBinaryString(binaryString)) + .join(""), + raws.beforeClose, + "}", + raws.after + ); + } + + private printIdentifierList(ast: AST.IdentifierList): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "[", + raws.afterOpen, + ast.values + .map((identifier) => this.printIdentifier(identifier)) + .join(","), + raws.beforeClose, + "]", + raws.after + ); + } + + private printItemList(ast: AST.ItemList): string { + const raws = this.raws(ast); + return this.print( + raws.before, + "<", + raws.afterOpen, + ast.values.map((item) => this.printItem(item)).join(""), + raws.beforeClose, + ">", + raws.after + ); + } + + private printProperty(ast: AST.Property): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.name, + raws.afterName, + "=", + raws.beforeValue, + this.stringify(ast.value), + raws.after + ); + } + + private printObject(ast: AST.DObject): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.kind, + raws.beforeName, + ast.name, + raws.afterName, + ast.type + ? this.print(":", raws.beforeType, ast.type, raws.afterType) + : "", + ast.order !== undefined + ? this.print( + "[", + raws.beforeOrder, + `${ast.order}`, + raws.afterOrder, + "]" + ) + : "", + ast.properties && ast.properties.length + ? this.print( + raws.beforeProperties, + ast.properties + .map((property) => this.printProperty(property)) + .join("") + ) + : "", + ast.children && ast.children.length + ? this.print( + raws.beforeChildren, + ast.children.map((child) => this.printObject(child)).join("") + ) + : "", + raws.beforeEnd, + "end", + raws.after + ); + } + + private printRoot(ast: AST.Root): string { + const raws = this.raws(ast); + return this.print( + raws.before, + ast.child ? this.printObject(ast.child) : "", + raws.after + ); + } + + private print(...values: (string | undefined)[]): string { + return values.filter((v) => !!v).join(""); + } + + private raws(obj: AST.ASTNode): R { + return obj.raws || {}; + } +} diff --git a/packages/@postdfm/ast2dfm/typedoc.config.js b/packages/@postdfm/ast2dfm/typedoc.config.js index d7545d5a..353a8bdd 100644 --- a/packages/@postdfm/ast2dfm/typedoc.config.js +++ b/packages/@postdfm/ast2dfm/typedoc.config.js @@ -1,3 +1,3 @@ -module.exports = require("../../../typedoc")({ - out: "@postdfm/ast2dfm" -}); +module.exports = require("../../../typedoc")({ + out: "@postdfm/ast2dfm", +}); diff --git a/packages/@postdfm/dfm2ast/.eslintrc.js b/packages/@postdfm/dfm2ast/.eslintrc.js index d177fd35..dad6750a 100644 --- a/packages/@postdfm/dfm2ast/.eslintrc.js +++ b/packages/@postdfm/dfm2ast/.eslintrc.js @@ -1 +1 @@ -module.exports = require("../../../eslint.config.js")(true); +module.exports = require("../../../eslint.config.js")(true); diff --git a/packages/@postdfm/dfm2ast/README.md b/packages/@postdfm/dfm2ast/README.md index 80ab6a46..fd84e860 100644 --- a/packages/@postdfm/dfm2ast/README.md +++ b/packages/@postdfm/dfm2ast/README.md @@ -1,12 +1,12 @@ -# @postdfm/dfm2ast - -[![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) -[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/dfm2ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/dfm2ast/package.json) - -Sub-package for `postdfm`. - -Provides functionality for parsing DFMs into the structures provided by `@postdfm/ast`. - -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/dfm2ast/). +# @postdfm/dfm2ast + +[![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/dfm2ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/dfm2ast/package.json) + +Sub-package for `postdfm`. + +Provides functionality for parsing DFMs into the structures provided by `@postdfm/ast`. + +See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/dfm2ast/). diff --git a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts index f1b57ff1..45060c33 100644 --- a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts @@ -1,22 +1,22 @@ -import * as fs from "fs"; -import * as path from "path"; -import parse from "../../src"; - -const rootFixturesDir = path.join("__test__", "__fixtures__"); -const parseFixturesDir = path.join(rootFixturesDir, "parse"); - -describe("dfm2ast", () => { - describe("fixtures", () => { - const fixtures = fs.readdirSync(parseFixturesDir); - fixtures.forEach(fixture => { - const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); - const astFile = path.join(parseFixturesDir, fixture, "ast.json"); - - test(fixture, () => { - expect( - JSON.parse(JSON.stringify(parse(fs.readFileSync(formFile, "ascii")))) - ).toEqual(JSON.parse(fs.readFileSync(astFile, "utf8"))); - }); - }); - }); -}); +import * as fs from "fs"; +import * as path from "path"; +import parse from "../../src"; + +const rootFixturesDir = path.join("__test__", "__fixtures__"); +const parseFixturesDir = path.join(rootFixturesDir, "parse"); + +describe("dfm2ast", () => { + describe("fixtures", () => { + const fixtures = fs.readdirSync(parseFixturesDir); + fixtures.forEach((fixture) => { + const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); + const astFile = path.join(parseFixturesDir, fixture, "ast.json"); + + test(fixture, () => { + expect( + JSON.parse(JSON.stringify(parse(fs.readFileSync(formFile, "ascii")))) + ).toEqual(JSON.parse(fs.readFileSync(astFile, "utf8"))); + }); + }); + }); +}); diff --git a/packages/@postdfm/dfm2ast/src/index.ts b/packages/@postdfm/dfm2ast/src/index.ts index 7bbeedf2..ab7bf6ed 100644 --- a/packages/@postdfm/dfm2ast/src/index.ts +++ b/packages/@postdfm/dfm2ast/src/index.ts @@ -1,25 +1,25 @@ -import { Root } from "@postdfm/ast"; -import { Grammar, Parser } from "nearley"; -import grammar from "./grammar"; - -function parse(dfm: string): Root { - const parser = new Parser(Grammar.fromCompiled(grammar)); - parser.feed(dfm); - - if (!parser.results.length) { - throw new Error("Unexpected End Of Input"); - } - - if (parser.results.length > 1) { - throw new Error( - `Ambiguous Grammar: ${parser.results.length} Results Found\n\n` + - " This probably isn't your fault. Please consider raising an " + - "issue with a reproducable case at github.com/spiltcoffee/postdfm" - ); - } - - return parser.results[0]; -} - -export default parse; -export { parse }; +import { Root } from "@postdfm/ast"; +import { Grammar, Parser } from "nearley"; +import grammar from "./grammar"; + +function parse(dfm: string): Root { + const parser = new Parser(Grammar.fromCompiled(grammar)); + parser.feed(dfm); + + if (!parser.results.length) { + throw new Error("Unexpected End Of Input"); + } + + if (parser.results.length > 1) { + throw new Error( + `Ambiguous Grammar: ${parser.results.length} Results Found\n\n` + + " This probably isn't your fault. Please consider raising an " + + "issue with a reproducable case at github.com/spiltcoffee/postdfm" + ); + } + + return parser.results[0]; +} + +export default parse; +export { parse }; diff --git a/packages/@postdfm/dfm2ast/typedoc.config.js b/packages/@postdfm/dfm2ast/typedoc.config.js index cc642e01..9b700ef7 100644 --- a/packages/@postdfm/dfm2ast/typedoc.config.js +++ b/packages/@postdfm/dfm2ast/typedoc.config.js @@ -1,3 +1,3 @@ -module.exports = require("../../../typedoc")({ - out: "@postdfm/dfm2ast" -}); +module.exports = require("../../../typedoc")({ + out: "@postdfm/dfm2ast", +}); diff --git a/packages/postdfm/.eslintrc.js b/packages/postdfm/.eslintrc.js index 4fa8a65b..1dc4a604 100644 --- a/packages/postdfm/.eslintrc.js +++ b/packages/postdfm/.eslintrc.js @@ -1 +1 @@ -module.exports = require("../../eslint.config.js")(true); +module.exports = require("../../eslint.config.js")(true); diff --git a/packages/postdfm/README.md b/packages/postdfm/README.md index 367cea5b..965ff640 100644 --- a/packages/postdfm/README.md +++ b/packages/postdfm/README.md @@ -1,142 +1,142 @@ -# postdfm - -> Process over Delphi Forms (.dfm) files via an AST. -> -> Inspired by the excellent PostCSS tool, motivated by my rage at the Delphi IDE. - -[![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) -[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/postdfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/postdfm/package.json) - -## Table of Contents - -- [Installation](#installation) -- [Example Usage](#example-usage) -- [Reference](#reference) -- [Contributing](#contributing) -- [License](#license) - -## Installation - -The `postdfm` project is an interface wrapping all the separate modules together. - -```shell -# npm -$ npm install postdfm - -# yarn -$ yarn add postdfm -``` - -## Example Usage - -```js -const fs = require("fs"); -const postdfm = require("postdfm"); - -const cisDfm = fs.readFileSync( - "cis.dfm", - //.dfm files tend to be ascii instead of utf8 - "ascii" -); - -const runner = postdfm({ - transformers: [ - function(ast) { - //transform and return the ast - return transformedAst; - } - ] -}); - -const transDfm = runner.processSync(dfm, { - //filename used for reporting errors - from: "cis.dfm" -}); - -fs.writeFileSync("trans.dfm", transDfm); -``` - -## Reference - -### `Runner` instance - -Create a runner by calling the `postdfm` function. - -```js -const postdfm = require("postdfm"); -const runner = postdfm(); -``` - -#### `postdfm(options?: RunnerOptions)` - -Create a `Runner` instance using `RunnerOptions` - -#### `runner.process(dfm: string, processingOptions: ProcessingOptions): Promise` - -Process a file through the runner asynchronously. - -#### `runner.processSync(dfm: string, processingOptions: ProcessingOptions): string` - -Process a file through the runner synchronously. - -### `RunnerOptions` - -Options to pass to an instance of `Runner`. - -#### `options.transformers: Transformer[]` - -Array of transformations to perform on AST. - -#### `options.parser: Parser = "@postdfm/dfm2ast"` - -Parser to use, defaults to `@postdfm/dfm2ast`. - -#### `options.stringifier: Stringifier = "@postdfm/ast2dfm"` - -Stringifier to use, defaults to `@postdfm/ast2dfm`. - -### `Transformer` - -A function that takes an AST, transforms it, and returns it. - -```js -(ast: AST.Root): AST.Root -``` - -### `Parser` - -A function that takes a string, parses it, and returns an AST. - -```js -(dfm: string): AST.Root -``` - -### `Stringifier` - -A function that takes an AST, stringifies it, and returns a string. - -```js -(ast: AST.Root): string -``` - -### `ProcessingOptions` - -#### `processingOptions.from` - -The file which is being processed. Used when throwing syntax errors. - -## Generated Documentation - -You can find the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/postdfm/). - -## Contributing - -Bug reports and feature requests are greatly appreciated, as are pull requests. - -Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/master/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. - -## License - -Licensed under the MIT License. +# postdfm + +> Process over Delphi Forms (.dfm) files via an AST. +> +> Inspired by the excellent PostCSS tool, motivated by my rage at the Delphi IDE. + +[![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/postdfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/postdfm/package.json) + +## Table of Contents + +- [Installation](#installation) +- [Example Usage](#example-usage) +- [Reference](#reference) +- [Contributing](#contributing) +- [License](#license) + +## Installation + +The `postdfm` project is an interface wrapping all the separate modules together. + +```shell +# npm +$ npm install postdfm + +# yarn +$ yarn add postdfm +``` + +## Example Usage + +```js +const fs = require("fs"); +const postdfm = require("postdfm"); + +const cisDfm = fs.readFileSync( + "cis.dfm", + //.dfm files tend to be ascii instead of utf8 + "ascii" +); + +const runner = postdfm({ + transformers: [ + function (ast) { + //transform and return the ast + return transformedAst; + }, + ], +}); + +const transDfm = runner.processSync(dfm, { + //filename used for reporting errors + from: "cis.dfm", +}); + +fs.writeFileSync("trans.dfm", transDfm); +``` + +## Reference + +### `Runner` instance + +Create a runner by calling the `postdfm` function. + +```js +const postdfm = require("postdfm"); +const runner = postdfm(); +``` + +#### `postdfm(options?: RunnerOptions)` + +Create a `Runner` instance using `RunnerOptions` + +#### `runner.process(dfm: string, processingOptions: ProcessingOptions): Promise` + +Process a file through the runner asynchronously. + +#### `runner.processSync(dfm: string, processingOptions: ProcessingOptions): string` + +Process a file through the runner synchronously. + +### `RunnerOptions` + +Options to pass to an instance of `Runner`. + +#### `options.transformers: Transformer[]` + +Array of transformations to perform on AST. + +#### `options.parser: Parser = "@postdfm/dfm2ast"` + +Parser to use, defaults to `@postdfm/dfm2ast`. + +#### `options.stringifier: Stringifier = "@postdfm/ast2dfm"` + +Stringifier to use, defaults to `@postdfm/ast2dfm`. + +### `Transformer` + +A function that takes an AST, transforms it, and returns it. + +```js +(ast: AST.Root): AST.Root +``` + +### `Parser` + +A function that takes a string, parses it, and returns an AST. + +```js +(dfm: string): AST.Root +``` + +### `Stringifier` + +A function that takes an AST, stringifies it, and returns a string. + +```js +(ast: AST.Root): string +``` + +### `ProcessingOptions` + +#### `processingOptions.from` + +The file which is being processed. Used when throwing syntax errors. + +## Generated Documentation + +You can find the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/postdfm/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/master/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/postdfm/__test__/broken/index.test.ts b/packages/postdfm/__test__/broken/index.test.ts index ab2adbb7..1744372b 100644 --- a/packages/postdfm/__test__/broken/index.test.ts +++ b/packages/postdfm/__test__/broken/index.test.ts @@ -1,41 +1,41 @@ -import * as fs from "fs"; -import * as path from "path"; -import postdfm from "../../src"; - -describe("postdfm", () => { - describe("broken DFMs throw errors", () => { - describe("unexpected end", () => { - const file = path.join(__dirname, "unexpectedEnd.dfm"); - const dfm = fs.readFileSync(file, "ascii"); - - test("without `from`", () => { - expect(() => postdfm().processSync(dfm)).toThrow( - /Unexpected End Of Input/ - ); - }); - - test("with `from`", () => { - expect(() => postdfm().processSync(dfm, { from: file })).toThrow( - /unexpectedEnd.dfm: Unexpected End Of Input/ - ); - }); - }); - - describe("invalid property", () => { - const file = path.join(__dirname, "invalidProperty.dfm"); - const dfm = fs.readFileSync(file, "ascii"); - - test("without `from`", () => { - expect(() => postdfm().processSync(dfm)).toThrow( - /Syntax error at line 3 col 1/ - ); - }); - - test("with `from`", () => { - expect(() => postdfm().processSync(dfm, { from: file })).toThrow( - /invalidProperty.dfm: Syntax error at line 3 col 1/ - ); - }); - }); - }); -}); +import * as fs from "fs"; +import * as path from "path"; +import postdfm from "../../src"; + +describe("postdfm", () => { + describe("broken DFMs throw errors", () => { + describe("unexpected end", () => { + const file = path.join(__dirname, "unexpectedEnd.dfm"); + const dfm = fs.readFileSync(file, "ascii"); + + test("without `from`", () => { + expect(() => postdfm().processSync(dfm)).toThrow( + /Unexpected End Of Input/ + ); + }); + + test("with `from`", () => { + expect(() => postdfm().processSync(dfm, { from: file })).toThrow( + /unexpectedEnd.dfm: Unexpected End Of Input/ + ); + }); + }); + + describe("invalid property", () => { + const file = path.join(__dirname, "invalidProperty.dfm"); + const dfm = fs.readFileSync(file, "ascii"); + + test("without `from`", () => { + expect(() => postdfm().processSync(dfm)).toThrow( + /Syntax error at line 3 col 1/ + ); + }); + + test("with `from`", () => { + expect(() => postdfm().processSync(dfm, { from: file })).toThrow( + /invalidProperty.dfm: Syntax error at line 3 col 1/ + ); + }); + }); + }); +}); diff --git a/packages/postdfm/__test__/fixtures/index.test.ts b/packages/postdfm/__test__/fixtures/index.test.ts index fa39ed66..ade5756a 100644 --- a/packages/postdfm/__test__/fixtures/index.test.ts +++ b/packages/postdfm/__test__/fixtures/index.test.ts @@ -1,70 +1,70 @@ -import * as fs from "fs"; -import * as path from "path"; -import postdfm from "../../src"; -import { Root } from "@postdfm/ast"; - -const rootFixturesDir = path.resolve("__test__", "__fixtures__"); -const parseFixturesDir = path.join(rootFixturesDir, "parse"); -const transformFixturesDir = path.join(rootFixturesDir, "transform"); - -function noopTransform(ast: Root): Root { - return ast; -} - -describe("postdfm", () => { - describe("parse fixtures", () => { - const runner = postdfm({ - transformers: [noopTransform] - }); - - const fixtures = fs.readdirSync(parseFixturesDir); - fixtures.forEach(fixture => { - const cisForm = fs.readFileSync( - path.join(parseFixturesDir, fixture, "form.dfm"), - "ascii" - ); - - describe(`${fixture}`, () => { - test("sync", () => { - expect(runner.processSync(cisForm)).toEqual(cisForm); - }); - - test("async", () => { - return runner - .process(cisForm) - .then(dfm => expect(dfm).toEqual(cisForm)); - }); - }); - }); - }); - - describe("transform fixtures", () => { - const fixtures = fs.readdirSync(transformFixturesDir); - fixtures.forEach(fixture => { - const fixtureDir = path.join(transformFixturesDir, fixture); - const cisForm = fs.readFileSync( - path.join(fixtureDir, "cis.dfm"), - "ascii" - ); - const transForm = fs.readFileSync( - path.join(fixtureDir, "trans.dfm"), - "ascii" - ); - const transformers = [require(path.join(fixtureDir, "transformer.js"))]; - - const runner = postdfm({ transformers }); - - describe(`${fixture}`, () => { - test("sync", () => { - expect(runner.processSync(cisForm)).toEqual(transForm); - }); - - test("async", () => { - return runner - .process(cisForm) - .then(dfm => expect(dfm).toEqual(transForm)); - }); - }); - }); - }); -}); +import * as fs from "fs"; +import * as path from "path"; +import postdfm from "../../src"; +import { Root } from "@postdfm/ast"; + +const rootFixturesDir = path.resolve("__test__", "__fixtures__"); +const parseFixturesDir = path.join(rootFixturesDir, "parse"); +const transformFixturesDir = path.join(rootFixturesDir, "transform"); + +function noopTransform(ast: Root): Root { + return ast; +} + +describe("postdfm", () => { + describe("parse fixtures", () => { + const runner = postdfm({ + transformers: [noopTransform], + }); + + const fixtures = fs.readdirSync(parseFixturesDir); + fixtures.forEach((fixture) => { + const cisForm = fs.readFileSync( + path.join(parseFixturesDir, fixture, "form.dfm"), + "ascii" + ); + + describe(`${fixture}`, () => { + test("sync", () => { + expect(runner.processSync(cisForm)).toEqual(cisForm); + }); + + test("async", () => { + return runner + .process(cisForm) + .then((dfm) => expect(dfm).toEqual(cisForm)); + }); + }); + }); + }); + + describe("transform fixtures", () => { + const fixtures = fs.readdirSync(transformFixturesDir); + fixtures.forEach((fixture) => { + const fixtureDir = path.join(transformFixturesDir, fixture); + const cisForm = fs.readFileSync( + path.join(fixtureDir, "cis.dfm"), + "ascii" + ); + const transForm = fs.readFileSync( + path.join(fixtureDir, "trans.dfm"), + "ascii" + ); + const transformers = [require(path.join(fixtureDir, "transformer.js"))]; + + const runner = postdfm({ transformers }); + + describe(`${fixture}`, () => { + test("sync", () => { + expect(runner.processSync(cisForm)).toEqual(transForm); + }); + + test("async", () => { + return runner + .process(cisForm) + .then((dfm) => expect(dfm).toEqual(transForm)); + }); + }); + }); + }); +}); diff --git a/packages/postdfm/__test__/options/index.test.ts b/packages/postdfm/__test__/options/index.test.ts index a21d3431..808ec53b 100644 --- a/packages/postdfm/__test__/options/index.test.ts +++ b/packages/postdfm/__test__/options/index.test.ts @@ -1,63 +1,63 @@ -import { stringify } from "@postdfm/ast2dfm"; -import { parse } from "@postdfm/dfm2ast"; -import * as path from "path"; -import postdfm, { RunnerOptions, Transformer } from "../../src"; -import { Root } from "@postdfm/ast"; - -function noopTransformer(ast: Root): Root { - return ast; -} - -describe("postdfm", () => { - describe("options", () => { - test("valid (normal)", () => { - const parser = parse; - const stringifier = stringify; - const transformers: Transformer[] = [noopTransformer]; - - postdfm(); - postdfm({ parser }); - postdfm({ stringifier }); - postdfm({ transformers }); - postdfm({ parser, stringifier }); - postdfm({ parser, transformers }); - postdfm({ stringifier, transformers }); - postdfm({ parser, stringifier, transformers }); - }); - - test("valid (using strings)", () => { - const parser = "@postdfm/dfm2ast"; - const stringifier = "@postdfm/ast2dfm"; - const transformers = [path.join(__dirname, "transformer.js")]; - - postdfm(); - postdfm({ parser }); - postdfm({ stringifier }); - postdfm({ transformers }); - postdfm({ parser, stringifier }); - postdfm({ parser, transformers }); - postdfm({ stringifier, transformers }); - postdfm({ parser, stringifier, transformers }); - }); - - test("invalid", () => { - const parser = true; - const stringifier = 5; - const transformer1 = {}; - const transformer2 = [5]; - - expect(() => postdfm(({ parser } as unknown) as RunnerOptions)).toThrow( - /parser must be a string or a function/ - ); - expect(() => - postdfm(({ stringifier } as unknown) as RunnerOptions) - ).toThrow(/stringifier must be a string or a function/); - expect(() => - postdfm(({ transformers: transformer1 } as unknown) as RunnerOptions) - ).toThrow(/transformers must be an array of strings and\/or functions/); - expect(() => - postdfm(({ transformers: transformer2 } as unknown) as RunnerOptions) - ).toThrow(/transformers must be an array of strings and\/or functions/); - }); - }); -}); +import { stringify } from "@postdfm/ast2dfm"; +import { parse } from "@postdfm/dfm2ast"; +import * as path from "path"; +import postdfm, { RunnerOptions, Transformer } from "../../src"; +import { Root } from "@postdfm/ast"; + +function noopTransformer(ast: Root): Root { + return ast; +} + +describe("postdfm", () => { + describe("options", () => { + test("valid (normal)", () => { + const parser = parse; + const stringifier = stringify; + const transformers: Transformer[] = [noopTransformer]; + + postdfm(); + postdfm({ parser }); + postdfm({ stringifier }); + postdfm({ transformers }); + postdfm({ parser, stringifier }); + postdfm({ parser, transformers }); + postdfm({ stringifier, transformers }); + postdfm({ parser, stringifier, transformers }); + }); + + test("valid (using strings)", () => { + const parser = "@postdfm/dfm2ast"; + const stringifier = "@postdfm/ast2dfm"; + const transformers = [path.join(__dirname, "transformer.js")]; + + postdfm(); + postdfm({ parser }); + postdfm({ stringifier }); + postdfm({ transformers }); + postdfm({ parser, stringifier }); + postdfm({ parser, transformers }); + postdfm({ stringifier, transformers }); + postdfm({ parser, stringifier, transformers }); + }); + + test("invalid", () => { + const parser = true; + const stringifier = 5; + const transformer1 = {}; + const transformer2 = [5]; + + expect(() => postdfm(({ parser } as unknown) as RunnerOptions)).toThrow( + /parser must be a string or a function/ + ); + expect(() => + postdfm(({ stringifier } as unknown) as RunnerOptions) + ).toThrow(/stringifier must be a string or a function/); + expect(() => + postdfm(({ transformers: transformer1 } as unknown) as RunnerOptions) + ).toThrow(/transformers must be an array of strings and\/or functions/); + expect(() => + postdfm(({ transformers: transformer2 } as unknown) as RunnerOptions) + ).toThrow(/transformers must be an array of strings and\/or functions/); + }); + }); +}); diff --git a/packages/postdfm/__test__/options/transformer.js b/packages/postdfm/__test__/options/transformer.js index 05f7696c..e48737e2 100644 --- a/packages/postdfm/__test__/options/transformer.js +++ b/packages/postdfm/__test__/options/transformer.js @@ -1 +1 @@ -module.exports = ast => ast; +module.exports = (ast) => ast; diff --git a/packages/postdfm/src/index.ts b/packages/postdfm/src/index.ts index 70678bad..ad1999ee 100644 --- a/packages/postdfm/src/index.ts +++ b/packages/postdfm/src/index.ts @@ -76,7 +76,7 @@ export default function postdfm(options?: RunnerOptions): Runner { const internalOptions: InternalRunnerOptions = { parser: parse, stringifier: stringify, - transformers: [] + transformers: [], }; if (options) { @@ -107,7 +107,7 @@ export default function postdfm(options?: RunnerOptions): Runner { ); } - options.transformers.forEach(transformer => { + options.transformers.forEach((transformer) => { let internalTransformer: Transformer; if (typeof transformer === "string") { internalTransformer = require(transformer); diff --git a/packages/postdfm/typedoc.config.js b/packages/postdfm/typedoc.config.js index 8f5fce73..5dc7f9a7 100644 --- a/packages/postdfm/typedoc.config.js +++ b/packages/postdfm/typedoc.config.js @@ -1,3 +1,3 @@ -module.exports = require("../../typedoc")({ - out: "postdfm" -}); +module.exports = require("../../typedoc")({ + out: "postdfm", +}); diff --git a/release.config.js b/release.config.js index e43ed7d4..4aba51e6 100644 --- a/release.config.js +++ b/release.config.js @@ -20,8 +20,8 @@ module.exports = { "@semantic-release/npm", { pkgRoot, - tarballDir - } + tarballDir, + }, ]), [ "@semantic-release/github", @@ -31,17 +31,17 @@ module.exports = { tarballDir, `${name.replace("@", "").replace("/", "-")}-*.tgz` ), - label: name - })) - } + label: name, + })), + }, ], [ "@semantic-release/git", { assets: [ - ["packages/**/package.json", "!**/node_modules/**/package.json"] - ] - } - ] - ] + ["packages/**/package.json", "!**/node_modules/**/package.json"], + ], + }, + ], + ], }; diff --git a/typedoc.js b/typedoc.js index a1272d14..568fcd98 100644 --- a/typedoc.js +++ b/typedoc.js @@ -1,13 +1,13 @@ -const path = require("path"); - -module.exports = options => - Object.assign( - { - excludePrivate: true, - theme: "minimal" - }, - options, - { - out: path.resolve(__dirname, "docs", options.out) - } - ); +const path = require("path"); + +module.exports = (options) => + Object.assign( + { + excludePrivate: true, + theme: "minimal", + }, + options, + { + out: path.resolve(__dirname, "docs", options.out), + } + ); From 28defd4e9e89ee023b858bf997f6b633a578cf25 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sun, 24 Jan 2021 14:57:19 +1100 Subject: [PATCH 05/26] build(eslint): upgrade eslint --- package.json | 12 +- yarn.lock | 409 +++++++++++++++++++++++++++------------------------ 2 files changed, 224 insertions(+), 197 deletions(-) diff --git a/package.json b/package.json index 8add9f09..52c4dfc7 100644 --- a/package.json +++ b/package.json @@ -30,14 +30,14 @@ "@types/jest": "^25.1.0", "@types/nearley": "^2.11.0", "@types/node": "^13.1.0", - "@typescript-eslint/eslint-plugin": "^2.1.0", - "@typescript-eslint/parser": "^2.1.0", + "@typescript-eslint/eslint-plugin": "^4.14.0", + "@typescript-eslint/parser": "^4.14.0", "commitlint": "^9.0.1", "cz-conventional-changelog": "^3.0.2", - "eslint": "^6.3.0", - "eslint-config-prettier": "^6.0.0", - "eslint-plugin-jest": "^23.0.0", - "eslint-plugin-node": "^11.0.0", + "eslint": "^7.18.0", + "eslint-config-prettier": "^7.2.0", + "eslint-plugin-jest": "^24.1.3", + "eslint-plugin-node": "^11.1.0", "execa": "^4.0.0", "husky": "^5.0.6", "jest": "^26.0.0", diff --git a/yarn.lock b/yarn.lock index 777f4c3c..3d6a8701 100644 --- a/yarn.lock +++ b/yarn.lock @@ -467,6 +467,22 @@ resolved "https://registry.yarnpkg.com/@commitlint/types/-/types-9.1.2.tgz#d05f66db03e3a3638a654e8badf2deb489eb220d" integrity sha512-r3fwVbVH+M8W0qYlBBZFsUwKe6NT5qvz+EmU7sr8VeN1cQ63z+3cfXyTo7WGGEMEgKiT0jboNAK3b1FZp8k9LQ== +"@eslint/eslintrc@^0.3.0": + version "0.3.0" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.3.0.tgz#d736d6963d7003b6514e6324bec9c602ac340318" + integrity sha512-1JTKgrOKAHVivSvOYw+sJOunkBjUOvjqWk1DPja7ZFhIS2mX/4EgTT8M7eTK9jrKhL/FvXXEbQwIs3pg1xp3dg== + dependencies: + ajv "^6.12.4" + debug "^4.1.1" + espree "^7.3.0" + globals "^12.1.0" + ignore "^4.0.6" + import-fresh "^3.2.1" + js-yaml "^3.13.1" + lodash "^4.17.20" + minimatch "^3.0.4" + strip-json-comments "^3.1.1" + "@iarna/cli@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@iarna/cli/-/cli-1.2.0.tgz#0f7af5e851afe895104583c4ca07377a8094d641" @@ -1147,11 +1163,6 @@ resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd" integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ== -"@types/eslint-visitor-keys@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" - integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== - "@types/graceful-fs@^4.1.2": version "4.1.3" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f" @@ -1315,49 +1326,77 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^2.1.0": - version "2.34.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9" - integrity sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ== +"@typescript-eslint/eslint-plugin@^4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.14.0.tgz#92db8e7c357ed7d69632d6843ca70b71be3a721d" + integrity sha512-IJ5e2W7uFNfg4qh9eHkHRUCbgZ8VKtGwD07kannJvM5t/GU8P8+24NX8gi3Hf5jST5oWPY8kyV1s/WtfiZ4+Ww== dependencies: - "@typescript-eslint/experimental-utils" "2.34.0" + "@typescript-eslint/experimental-utils" "4.14.0" + "@typescript-eslint/scope-manager" "4.14.0" + debug "^4.1.1" functional-red-black-tree "^1.0.1" + lodash "^4.17.15" regexpp "^3.0.0" + semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@2.34.0", "@typescript-eslint/experimental-utils@^2.5.0": - version "2.34.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz#d3524b644cdb40eebceca67f8cf3e4cc9c8f980f" - integrity sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA== +"@typescript-eslint/experimental-utils@4.14.0", "@typescript-eslint/experimental-utils@^4.0.1": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.14.0.tgz#5aa7b006736634f588a69ee343ca959cd09988df" + integrity sha512-6i6eAoiPlXMKRbXzvoQD5Yn9L7k9ezzGRvzC/x1V3650rUk3c3AOjQyGYyF9BDxQQDK2ElmKOZRD0CbtdkMzQQ== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/typescript-estree" "2.34.0" + "@typescript-eslint/scope-manager" "4.14.0" + "@typescript-eslint/types" "4.14.0" + "@typescript-eslint/typescript-estree" "4.14.0" eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@^2.1.0": - version "2.34.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.34.0.tgz#50252630ca319685420e9a39ca05fe185a256bc8" - integrity sha512-03ilO0ucSD0EPTw2X4PntSIRFtDPWjrVq7C3/Z3VQHRC7+13YB55rcJI3Jt+YgeHbjUdJPcPa7b23rXCBokuyA== +"@typescript-eslint/parser@^4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.14.0.tgz#62d4cd2079d5c06683e9bfb200c758f292c4dee7" + integrity sha512-sUDeuCjBU+ZF3Lzw0hphTyScmDDJ5QVkyE21pRoBo8iDl7WBtVFS+WDN3blY1CH3SBt7EmYCw6wfmJjF0l/uYg== dependencies: - "@types/eslint-visitor-keys" "^1.0.0" - "@typescript-eslint/experimental-utils" "2.34.0" - "@typescript-eslint/typescript-estree" "2.34.0" - eslint-visitor-keys "^1.1.0" + "@typescript-eslint/scope-manager" "4.14.0" + "@typescript-eslint/types" "4.14.0" + "@typescript-eslint/typescript-estree" "4.14.0" + debug "^4.1.1" -"@typescript-eslint/typescript-estree@2.34.0": - version "2.34.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5" - integrity sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg== +"@typescript-eslint/scope-manager@4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.14.0.tgz#55a4743095d684e1f7b7180c4bac2a0a3727f517" + integrity sha512-/J+LlRMdbPh4RdL4hfP1eCwHN5bAhFAGOTsvE6SxsrM/47XQiPSgF5MDgLyp/i9kbZV9Lx80DW0OpPkzL+uf8Q== dependencies: + "@typescript-eslint/types" "4.14.0" + "@typescript-eslint/visitor-keys" "4.14.0" + +"@typescript-eslint/types@4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.14.0.tgz#d8a8202d9b58831d6fd9cee2ba12f8a5a5dd44b6" + integrity sha512-VsQE4VvpldHrTFuVPY1ZnHn/Txw6cZGjL48e+iBxTi2ksa9DmebKjAeFmTVAYoSkTk7gjA7UqJ7pIsyifTsI4A== + +"@typescript-eslint/typescript-estree@4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.14.0.tgz#4bcd67486e9acafc3d0c982b23a9ab8ac8911ed7" + integrity sha512-wRjZ5qLao+bvS2F7pX4qi2oLcOONIB+ru8RGBieDptq/SudYwshveORwCVU4/yMAd4GK7Fsf8Uq1tjV838erag== + dependencies: + "@typescript-eslint/types" "4.14.0" + "@typescript-eslint/visitor-keys" "4.14.0" debug "^4.1.1" - eslint-visitor-keys "^1.1.0" - glob "^7.1.6" + globby "^11.0.1" is-glob "^4.0.1" lodash "^4.17.15" semver "^7.3.2" tsutils "^3.17.1" +"@typescript-eslint/visitor-keys@4.14.0": + version "4.14.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.14.0.tgz#b1090d9d2955b044b2ea2904a22496849acbdf54" + integrity sha512-MeHHzUyRI50DuiPgV9+LxcM52FCJFYjJiWHtXlbyC27b80mfOwKeiKI+MHOTEpcpfmoPFm/vvQS88bYIx6PZTA== + dependencies: + "@typescript-eslint/types" "4.14.0" + eslint-visitor-keys "^2.0.0" + "@yarnpkg/lockfile@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31" @@ -1389,10 +1428,10 @@ acorn-globals@^6.0.0: acorn "^7.1.1" acorn-walk "^7.1.1" -acorn-jsx@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe" - integrity sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ== +acorn-jsx@^5.3.1: + version "5.3.1" + resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b" + integrity sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng== acorn-walk@^7.1.1: version "7.2.0" @@ -1404,6 +1443,11 @@ acorn@^7.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.3.1.tgz#85010754db53c3fbaf3b9ea3e083aa5c5d147ffd" integrity sha512-tLc0wSnatxAQHVHUapaHdz72pi9KUyHjq5KyHjGg9Y8Ifdc79pTh2XvI6I1/chZbnM7QtNKzh66ooDogPZSleA== +acorn@^7.4.0: + version "7.4.1" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" + integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== + agent-base@4, agent-base@^4.2.0, agent-base@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee" @@ -1440,7 +1484,7 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" -ajv@^6.10.0, ajv@^6.10.2: +ajv@^6.10.0: version "6.12.2" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.2.tgz#c629c5eced17baf314437918d2da88c99d5958cd" integrity sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ== @@ -1450,7 +1494,7 @@ ajv@^6.10.0, ajv@^6.10.2: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^6.12.3: +ajv@^6.12.3, ajv@^6.12.4: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -1460,6 +1504,16 @@ ajv@^6.12.3: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ajv@^7.0.2: + version "7.0.3" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-7.0.3.tgz#13ae747eff125cafb230ac504b2406cf371eece2" + integrity sha512-R50QRlXSxqXcQP5SvKUrw8VZeypvo12i2IX0EeR5PiZ7bEKeHWgzgo264LDadUsCU42lTJVhFikTqJwNeH34gQ== + dependencies: + fast-deep-equal "^3.1.1" + json-schema-traverse "^1.0.0" + require-from-string "^2.0.2" + uri-js "^4.2.2" + ansi-align@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f" @@ -1650,11 +1704,6 @@ ast-types@0.x.x: dependencies: tslib "^2.0.1" -astral-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" - integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== - astral-regex@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" @@ -2081,7 +2130,7 @@ chalk@4.1.0, chalk@^4.0.0, chalk@^4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -2604,7 +2653,7 @@ cross-spawn@^5.0.1: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^6.0.0, cross-spawn@^6.0.5: +cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== @@ -2615,7 +2664,7 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0, cross-spawn@^7.0.3: +cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== @@ -2788,7 +2837,7 @@ deep-extend@^0.6.0: resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== -deep-is@~0.1.3: +deep-is@^0.1.3, deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= @@ -3097,7 +3146,7 @@ endian-reader@^0.3.0: resolved "https://registry.yarnpkg.com/endian-reader/-/endian-reader-0.3.0.tgz#84eca436b80aed0d0639c47291338b932efe50a0" integrity sha1-hOykNrgK7Q0GOcRykTOLky7+UKA= -enquirer@^2.3.6: +enquirer@^2.3.5, enquirer@^2.3.6: version "2.3.6" resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d" integrity sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== @@ -3207,12 +3256,10 @@ escodegen@1.x.x, escodegen@^1.14.1: optionalDependencies: source-map "~0.6.1" -eslint-config-prettier@^6.0.0: - version "6.15.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz#7f93f6cb7d45a92f1537a70ecc06366e1ac6fed9" - integrity sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw== - dependencies: - get-stdin "^6.0.0" +eslint-config-prettier@^7.2.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-7.2.0.tgz#f4a4bd2832e810e8cc7c1411ec85b3e85c0c53f9" + integrity sha512-rV4Qu0C3nfJKPOAhFujFxB7RMP+URFyQqqOZW9DMRD7ZDTFyjaIlETU3xzHELt++4ugC0+Jm084HQYkkJe+Ivg== eslint-plugin-es@^3.0.0: version "3.0.1" @@ -3222,14 +3269,14 @@ eslint-plugin-es@^3.0.0: eslint-utils "^2.0.0" regexpp "^3.0.0" -eslint-plugin-jest@^23.0.0: - version "23.20.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.20.0.tgz#e1d69c75f639e99d836642453c4e75ed22da4099" - integrity sha512-+6BGQt85OREevBDWCvhqj1yYA4+BFK4XnRZSGJionuEYmcglMZYLNNBBemwzbqUAckURaHdJSBcjHPyrtypZOw== +eslint-plugin-jest@^24.1.3: + version "24.1.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-24.1.3.tgz#fa3db864f06c5623ff43485ca6c0e8fc5fe8ba0c" + integrity sha512-dNGGjzuEzCE3d5EPZQ/QGtmlMotqnYWD/QpCZ1UuZlrMAdhG5rldh0N0haCvhGnUkSeuORS5VNROwF9Hrgn3Lg== dependencies: - "@typescript-eslint/experimental-utils" "^2.5.0" + "@typescript-eslint/experimental-utils" "^4.0.1" -eslint-plugin-node@^11.0.0: +eslint-plugin-node@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz#c95544416ee4ada26740a30474eefc5402dc671d" integrity sha512-oUwtPJ1W0SKD0Tr+wqu92c5xuCeQqB3hSCHasn/ZgjFdA9iDGNkNf2Zi9ztY7X+hNuMib23LNGRm6+uN+KLE3g== @@ -3241,7 +3288,7 @@ eslint-plugin-node@^11.0.0: resolve "^1.10.1" semver "^6.1.0" -eslint-scope@^5.0.0: +eslint-scope@^5.0.0, eslint-scope@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c" integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw== @@ -3249,76 +3296,74 @@ eslint-scope@^5.0.0: esrecurse "^4.3.0" estraverse "^4.1.1" -eslint-utils@^1.4.3: - version "1.4.3" - resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.3.tgz#74fec7c54d0776b6f67e0251040b5806564e981f" - integrity sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q== - dependencies: - eslint-visitor-keys "^1.1.0" - -eslint-utils@^2.0.0: +eslint-utils@^2.0.0, eslint-utils@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== dependencies: eslint-visitor-keys "^1.1.0" -eslint-visitor-keys@^1.1.0: +eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e" integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== -eslint@^6.3.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.8.0.tgz#62262d6729739f9275723824302fb227c8c93ffb" - integrity sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig== +eslint-visitor-keys@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8" + integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ== + +eslint@^7.18.0: + version "7.18.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.18.0.tgz#7fdcd2f3715a41fe6295a16234bd69aed2c75e67" + integrity sha512-fbgTiE8BfUJZuBeq2Yi7J3RB3WGUQ9PNuNbmgi6jt9Iv8qrkxfy19Ds3OpL1Pm7zg3BtTVhvcUZbIRQ0wmSjAQ== dependencies: "@babel/code-frame" "^7.0.0" + "@eslint/eslintrc" "^0.3.0" ajv "^6.10.0" - chalk "^2.1.0" - cross-spawn "^6.0.5" + chalk "^4.0.0" + cross-spawn "^7.0.2" debug "^4.0.1" doctrine "^3.0.0" - eslint-scope "^5.0.0" - eslint-utils "^1.4.3" - eslint-visitor-keys "^1.1.0" - espree "^6.1.2" - esquery "^1.0.1" + enquirer "^2.3.5" + eslint-scope "^5.1.1" + eslint-utils "^2.1.0" + eslint-visitor-keys "^2.0.0" + espree "^7.3.1" + esquery "^1.2.0" esutils "^2.0.2" - file-entry-cache "^5.0.1" + file-entry-cache "^6.0.0" functional-red-black-tree "^1.0.1" glob-parent "^5.0.0" globals "^12.1.0" ignore "^4.0.6" import-fresh "^3.0.0" imurmurhash "^0.1.4" - inquirer "^7.0.0" is-glob "^4.0.0" js-yaml "^3.13.1" json-stable-stringify-without-jsonify "^1.0.1" - levn "^0.3.0" - lodash "^4.17.14" + levn "^0.4.1" + lodash "^4.17.20" minimatch "^3.0.4" - mkdirp "^0.5.1" natural-compare "^1.4.0" - optionator "^0.8.3" + optionator "^0.9.1" progress "^2.0.0" - regexpp "^2.0.1" - semver "^6.1.2" - strip-ansi "^5.2.0" - strip-json-comments "^3.0.1" - table "^5.2.3" + regexpp "^3.1.0" + semver "^7.2.1" + strip-ansi "^6.0.0" + strip-json-comments "^3.1.0" + table "^6.0.4" text-table "^0.2.0" v8-compile-cache "^2.0.3" -espree@^6.1.2: - version "6.2.1" - resolved "https://registry.yarnpkg.com/espree/-/espree-6.2.1.tgz#77fc72e1fd744a2052c20f38a5b575832e82734a" - integrity sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw== +espree@^7.3.0, espree@^7.3.1: + version "7.3.1" + resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.1.tgz#f2df330b752c6f55019f8bd89b7660039c1bbbb6" + integrity sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g== dependencies: - acorn "^7.1.1" - acorn-jsx "^5.2.0" - eslint-visitor-keys "^1.1.0" + acorn "^7.4.0" + acorn-jsx "^5.3.1" + eslint-visitor-keys "^1.3.0" esprima@3.x.x: version "3.1.3" @@ -3330,7 +3375,7 @@ esprima@^4.0.0, esprima@^4.0.1, esprima@~4.0.0: resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== -esquery@^1.0.1: +esquery@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.3.1.tgz#b78b5828aa8e214e29fb74c4d5b752e1c033da57" integrity sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ== @@ -3544,7 +3589,7 @@ fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0: resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== -fast-levenshtein@~2.0.6: +fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= @@ -3582,12 +3627,12 @@ figures@^3.0.0, figures@^3.2.0: dependencies: escape-string-regexp "^1.0.5" -file-entry-cache@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c" - integrity sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g== +file-entry-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.0.tgz#7921a89c391c6d93efec2169ac6bf300c527ea0a" + integrity sha512-fqoO76jZ3ZnYrXLDRxBR1YvOvc0k844kcOg40bgsPrE25LAb/PDqTY+ho64Xh2c8ZXgIKldchCFHczG2UVRcWA== dependencies: - flat-cache "^2.0.1" + flat-cache "^3.0.4" file-uri-to-path@1: version "1.0.0" @@ -3668,19 +3713,18 @@ findup-sync@^3.0.0: micromatch "^3.0.4" resolve-dir "^1.0.1" -flat-cache@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0" - integrity sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA== +flat-cache@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" + integrity sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg== dependencies: - flatted "^2.0.0" - rimraf "2.6.3" - write "1.0.3" + flatted "^3.1.0" + rimraf "^3.0.2" -flatted@^2.0.0: - version "2.0.2" - resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" - integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== +flatted@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469" + integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA== flush-write-stream@^1.0.0: version "1.1.1" @@ -3885,11 +3929,6 @@ get-stdin@7.0.0: resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-7.0.0.tgz#8d5de98f15171a125c5e516643c7a6d0ea8a96f6" integrity sha512-zRKcywvrXlXsA0v0i9Io4KDRaAw7+a1ZpjRwl9Wox8PFlVCCHra7E9c4kqXCoCM9nR5tBkaTTZRBoCm60bFqTQ== -get-stdin@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" - integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== - get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -4510,25 +4549,6 @@ inquirer@6.5.2: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^7.0.0: - version "7.2.0" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.2.0.tgz#63ce99d823090de7eb420e4bb05e6f3449aa389a" - integrity sha512-E0c4rPwr9ByePfNlTIB8z51kK1s2n6jrHuJeEHENl/sbq2G/S1auvibgEwNR4uSyiU+PiYHqSwsgGiXjG8p5ZQ== - dependencies: - ansi-escapes "^4.2.1" - chalk "^3.0.0" - cli-cursor "^3.1.0" - cli-width "^2.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.15" - mute-stream "0.0.8" - run-async "^2.4.0" - rxjs "^6.5.3" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - inquirer@^7.3.3: version "7.3.3" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.3.tgz#04d176b2af04afc157a83fd7c100e98ee0aad003" @@ -5481,6 +5501,11 @@ json-schema-traverse@^0.4.1: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== +json-schema-traverse@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" + integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== + json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" @@ -5628,7 +5653,15 @@ leven@^3.1.0: resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" integrity sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A== -levn@^0.3.0, levn@~0.3.0: +levn@^0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" + integrity sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ== + dependencies: + prelude-ls "^1.2.1" + type-check "~0.4.0" + +levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4= @@ -6049,7 +6082,7 @@ lodash.without@~4.4.0: resolved "https://registry.yarnpkg.com/lodash.without/-/lodash.without-4.4.0.tgz#3cd4574a00b67bae373a94b748772640507b7aac" integrity sha1-PNRXSgC2e643OpS3SHcmQFB7eqw= -lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4: +lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== @@ -6995,7 +7028,7 @@ opener@^1.5.1: resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598" integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A== -optionator@^0.8.1, optionator@^0.8.3: +optionator@^0.8.1: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" integrity sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA== @@ -7007,6 +7040,18 @@ optionator@^0.8.1, optionator@^0.8.3: type-check "~0.3.2" word-wrap "~1.2.3" +optionator@^0.9.1: + version "0.9.1" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" + integrity sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw== + dependencies: + deep-is "^0.1.3" + fast-levenshtein "^2.0.6" + levn "^0.4.1" + prelude-ls "^1.2.1" + type-check "^0.4.0" + word-wrap "^1.2.3" + os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -7413,6 +7458,11 @@ posix-character-classes@^0.1.0: resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab" integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs= +prelude-ls@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" + integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" @@ -7845,12 +7895,7 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" -regexpp@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" - integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== - -regexpp@^3.0.0: +regexpp@^3.0.0, regexpp@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q== @@ -7946,6 +7991,11 @@ require-directory@^2.1.1: resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= +require-from-string@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" + integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== + require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" @@ -8063,13 +8113,6 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -rimraf@2.6.3: - version "2.6.3" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" - integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== - dependencies: - glob "^7.1.3" - rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.2, rimraf@^2.6.3, rimraf@^2.7.1: version "2.7.1" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" @@ -8113,13 +8156,6 @@ rxjs@^6.4.0, rxjs@^6.6.0, rxjs@^6.6.3: dependencies: tslib "^1.9.0" -rxjs@^6.5.3: - version "6.5.5" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.5.tgz#c5c884e3094c8cfee31bf27eb87e54ccfc87f9ec" - integrity sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ== - dependencies: - tslib "^1.9.0" - safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -8237,7 +8273,7 @@ semver@7.3.2: resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== -semver@7.x, semver@^7.1.2, semver@^7.3.2: +semver@7.x, semver@^7.1.2, semver@^7.2.1, semver@^7.3.2: version "7.3.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw== @@ -8343,15 +8379,6 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -slice-ansi@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" - integrity sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ== - dependencies: - ansi-styles "^3.2.0" - astral-regex "^1.0.0" - is-fullwidth-code-point "^2.0.0" - slice-ansi@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-3.0.0.tgz#31ddc10930a1b7e0b67b08c96c2f49b77a789787" @@ -9146,10 +9173,10 @@ strip-json-comments@3.0.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.0.1.tgz#85713975a91fb87bf1b305cca77395e40d2a64a7" integrity sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw== -strip-json-comments@^3.0.1: - version "3.1.0" - resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.0.tgz#7638d31422129ecf4457440009fba03f9f9ac180" - integrity sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w== +strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" + integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== strip-json-comments@~2.0.1: version "2.0.1" @@ -9183,15 +9210,15 @@ symbol-tree@^3.2.4: resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw== -table@^5.2.3: - version "5.4.6" - resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e" - integrity sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug== +table@^6.0.4: + version "6.0.7" + resolved "https://registry.yarnpkg.com/table/-/table-6.0.7.tgz#e45897ffbcc1bcf9e8a87bf420f2c9e5a7a52a34" + integrity sha512-rxZevLGTUzWna/qBLObOe16kB2RTnnbhciwgPbMMlazz1yZGVEgnZK762xyVdVznhqxrfCeBMmMkgOOaPwjH7g== dependencies: - ajv "^6.10.2" - lodash "^4.17.14" - slice-ansi "^2.1.0" - string-width "^3.0.0" + ajv "^7.0.2" + lodash "^4.17.20" + slice-ansi "^4.0.0" + string-width "^4.2.0" tar-stream@^2.1.0, tar-stream@^2.1.2: version "2.1.4" @@ -9513,6 +9540,13 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= +type-check@^0.4.0, type-check@~0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" + integrity sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew== + dependencies: + prelude-ls "^1.2.1" + type-check@~0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" @@ -9939,7 +9973,7 @@ windows-release@^3.1.0: dependencies: execa "^1.0.0" -word-wrap@^1.0.3, word-wrap@~1.2.3: +word-wrap@^1.0.3, word-wrap@^1.2.3, word-wrap@~1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== @@ -10036,13 +10070,6 @@ write-pkg@^4.0.0: type-fest "^0.4.1" write-json-file "^3.2.0" -write@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3" - integrity sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== - dependencies: - mkdirp "^0.5.1" - ws@^7.2.3: version "7.4.0" resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.0.tgz#a5dd76a24197940d4a8bb9e0e152bb4503764da7" From 29eac76ae5a7ca47216f4214bb9ad59e58aac74d Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sun, 24 Jan 2021 14:54:04 +1100 Subject: [PATCH 06/26] chore: fixed lint issues --- eslint.config.js | 1 + packages/@postdfm/ast/__test__/root.test.ts | 4 +-- .../ast2dfm/__test__/fixtures/index.test.ts | 2 +- .../dfm2ast/__test__/fixtures/index.test.ts | 2 +- packages/@postdfm/dfm2ast/src/index.ts | 2 +- .../postdfm/__test__/options/index.test.ts | 36 ++++++++++--------- packages/postdfm/src/index.ts | 15 +++++--- 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 43a5ab0b..2834c425 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,6 +8,7 @@ module.exports = function getConfig(enableTypeChecking) { tryExtensions: [".js", ".ts", ".json", ".node"], }, }, + ignorePatterns: [".eslintrc.js"], parserOptions: { project: "./tsconfig.json", }, diff --git a/packages/@postdfm/ast/__test__/root.test.ts b/packages/@postdfm/ast/__test__/root.test.ts index 513787bf..76f2cc5e 100644 --- a/packages/@postdfm/ast/__test__/root.test.ts +++ b/packages/@postdfm/ast/__test__/root.test.ts @@ -17,8 +17,6 @@ describe("creating FormObjects", () => { const node = new AST.Root(objectNode); expect(node.child).toBeDefined(); - if (node.child) { - expect(node.child.kind).toBe(AST.ObjectKind.Inherited); - } + expect(node.child?.kind).toBe(AST.ObjectKind.Inherited); }); }); diff --git a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts index b6787cfc..b7b338a9 100644 --- a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts @@ -13,7 +13,7 @@ describe("dfm2ast", () => { const astFile = path.join(parseFixturesDir, fixture, "ast.json"); const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); - test(fixture, () => { + test(`${fixture}`, () => { expect( stringify(JSON.parse(fs.readFileSync(astFile, "utf8")) as AST.Root) ).toEqual(fs.readFileSync(formFile, "ascii")); diff --git a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts index 45060c33..70e2de0b 100644 --- a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts @@ -12,7 +12,7 @@ describe("dfm2ast", () => { const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); const astFile = path.join(parseFixturesDir, fixture, "ast.json"); - test(fixture, () => { + test(`${fixture}`, () => { expect( JSON.parse(JSON.stringify(parse(fs.readFileSync(formFile, "ascii")))) ).toEqual(JSON.parse(fs.readFileSync(astFile, "utf8"))); diff --git a/packages/@postdfm/dfm2ast/src/index.ts b/packages/@postdfm/dfm2ast/src/index.ts index ab7bf6ed..b68b9245 100644 --- a/packages/@postdfm/dfm2ast/src/index.ts +++ b/packages/@postdfm/dfm2ast/src/index.ts @@ -18,7 +18,7 @@ function parse(dfm: string): Root { ); } - return parser.results[0]; + return parser.results[0] as Root; } export default parse; diff --git a/packages/postdfm/__test__/options/index.test.ts b/packages/postdfm/__test__/options/index.test.ts index 808ec53b..ed9893a5 100644 --- a/packages/postdfm/__test__/options/index.test.ts +++ b/packages/postdfm/__test__/options/index.test.ts @@ -15,14 +15,17 @@ describe("postdfm", () => { const stringifier = stringify; const transformers: Transformer[] = [noopTransformer]; - postdfm(); - postdfm({ parser }); - postdfm({ stringifier }); - postdfm({ transformers }); - postdfm({ parser, stringifier }); - postdfm({ parser, transformers }); - postdfm({ stringifier, transformers }); - postdfm({ parser, stringifier, transformers }); + expect(() => postdfm()).not.toThrow(); + expect(() => postdfm()).not.toThrow(); + expect(() => postdfm({ parser })).not.toThrow(); + expect(() => postdfm({ stringifier })).not.toThrow(); + expect(() => postdfm({ transformers })).not.toThrow(); + expect(() => postdfm({ parser, stringifier })).not.toThrow(); + expect(() => postdfm({ parser, transformers })).not.toThrow(); + expect(() => postdfm({ stringifier, transformers })).not.toThrow(); + expect(() => + postdfm({ parser, stringifier, transformers }) + ).not.toThrow(); }); test("valid (using strings)", () => { @@ -30,14 +33,15 @@ describe("postdfm", () => { const stringifier = "@postdfm/ast2dfm"; const transformers = [path.join(__dirname, "transformer.js")]; - postdfm(); - postdfm({ parser }); - postdfm({ stringifier }); - postdfm({ transformers }); - postdfm({ parser, stringifier }); - postdfm({ parser, transformers }); - postdfm({ stringifier, transformers }); - postdfm({ parser, stringifier, transformers }); + expect(() => postdfm({ parser })).not.toThrow(); + expect(() => postdfm({ stringifier })).not.toThrow(); + expect(() => postdfm({ transformers })).not.toThrow(); + expect(() => postdfm({ parser, stringifier })).not.toThrow(); + expect(() => postdfm({ parser, transformers })).not.toThrow(); + expect(() => postdfm({ stringifier, transformers })).not.toThrow(); + expect(() => + postdfm({ parser, stringifier, transformers }) + ).not.toThrow(); }); test("invalid", () => { diff --git a/packages/postdfm/src/index.ts b/packages/postdfm/src/index.ts index ad1999ee..88b5a32f 100644 --- a/packages/postdfm/src/index.ts +++ b/packages/postdfm/src/index.ts @@ -40,7 +40,11 @@ export class Runner { ast = this.options.parser(dfm); } catch (error) { if (processingOptions && processingOptions.from) { - throw new Error(`Error in ${processingOptions.from}: ${error.message}`); + throw new Error( + `Error in ${processingOptions.from}: ${ + (<{ message: string }>error).message + }` + ); } else { throw error; } @@ -82,7 +86,8 @@ export default function postdfm(options?: RunnerOptions): Runner { if (options) { if (options.parser) { if (typeof options.parser === "string") { - internalOptions.parser = require(options.parser); + // eslint-disable-next-line @typescript-eslint/no-var-requires + internalOptions.parser = require(options.parser) as Parser; } else if (typeof options.parser === "function") { internalOptions.parser = options.parser; } else { @@ -92,7 +97,8 @@ export default function postdfm(options?: RunnerOptions): Runner { if (options.stringifier) { if (typeof options.stringifier === "string") { - internalOptions.stringifier = require(options.stringifier); + // eslint-disable-next-line @typescript-eslint/no-var-requires + internalOptions.stringifier = require(options.stringifier) as Stringifier; } else if (typeof options.stringifier === "function") { internalOptions.stringifier = options.stringifier; } else { @@ -110,7 +116,8 @@ export default function postdfm(options?: RunnerOptions): Runner { options.transformers.forEach((transformer) => { let internalTransformer: Transformer; if (typeof transformer === "string") { - internalTransformer = require(transformer); + // eslint-disable-next-line @typescript-eslint/no-var-requires + internalTransformer = require(transformer) as Transformer; } else if (typeof transformer === "function") { internalTransformer = transformer; } else { From a0a1bac7038d391bd211603b81a7dd419f07071a Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:42:19 +1100 Subject: [PATCH 07/26] build(typescript): update typescript --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 52c4dfc7..74c0e51e 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "semantic-release": "^17.3.1", "ts-jest": "^26.4.4", "typedoc": "^0.19.2", - "typescript": "^3.3.3333", + "typescript": "^4.1.3", "write-pkg": "^4.0.0" }, "config": { diff --git a/yarn.lock b/yarn.lock index 3d6a8701..1e7f2d76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9628,10 +9628,10 @@ typedoc@^0.19.2: shelljs "^0.8.4" typedoc-default-themes "^0.11.4" -typescript@^3.3.3333: - version "3.9.7" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa" - integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw== +typescript@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" + integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== uglify-js@^3.1.4: version "3.9.4" From ec48a7288815864a617144096cf900b8247f8584 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:45:44 +1100 Subject: [PATCH 08/26] feat(@postdfm/plugin): added @postdfm/plugin fix #198 --- packages/@postdfm/plugin/.eslintrc.js | 1 + packages/@postdfm/plugin/README.md | 12 ++ .../plugin/__test__/plugin/index.test.ts | 33 +++++ packages/@postdfm/plugin/package.json | 31 +++++ packages/@postdfm/plugin/src/hooks.ts | 126 ++++++++++++++++++ packages/@postdfm/plugin/src/index.ts | 2 + packages/@postdfm/plugin/src/plugin.ts | 5 + packages/@postdfm/plugin/tsconfig.json | 7 + packages/@postdfm/plugin/typedoc.config.js | 3 + yarn.lock | 5 + 10 files changed, 225 insertions(+) create mode 100644 packages/@postdfm/plugin/.eslintrc.js create mode 100644 packages/@postdfm/plugin/README.md create mode 100644 packages/@postdfm/plugin/__test__/plugin/index.test.ts create mode 100644 packages/@postdfm/plugin/package.json create mode 100644 packages/@postdfm/plugin/src/hooks.ts create mode 100644 packages/@postdfm/plugin/src/index.ts create mode 100644 packages/@postdfm/plugin/src/plugin.ts create mode 100644 packages/@postdfm/plugin/tsconfig.json create mode 100644 packages/@postdfm/plugin/typedoc.config.js diff --git a/packages/@postdfm/plugin/.eslintrc.js b/packages/@postdfm/plugin/.eslintrc.js new file mode 100644 index 00000000..dad6750a --- /dev/null +++ b/packages/@postdfm/plugin/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require("../../../eslint.config.js")(true); diff --git a/packages/@postdfm/plugin/README.md b/packages/@postdfm/plugin/README.md new file mode 100644 index 00000000..78e16222 --- /dev/null +++ b/packages/@postdfm/plugin/README.md @@ -0,0 +1,12 @@ +# @postdfm/plugin + +[![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/plugin/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/plugin/package.json) + +Sub-package for `postdfm`. + +Provides structure and utilities for making plugins that can modify a `@postdfm/ast` Abstract Syntax Tree. + +See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/plugin/). diff --git a/packages/@postdfm/plugin/__test__/plugin/index.test.ts b/packages/@postdfm/plugin/__test__/plugin/index.test.ts new file mode 100644 index 00000000..ed86b8fa --- /dev/null +++ b/packages/@postdfm/plugin/__test__/plugin/index.test.ts @@ -0,0 +1,33 @@ +import * as AST from "@postdfm/ast"; +import { Plugin, Hooks } from "../../src"; + +class TapAllPlugin extends Plugin { + hookCallback: () => void; + + constructor(hookCallback: () => void) { + super(); + this.hookCallback = hookCallback; + } + + install(hooks: Hooks): void { + hooks.all.tap("TapAllPlugin", () => { + this.hookCallback(); + }); + } +} + +describe("plugin", () => { + test("all hooks are tapable and callable", () => { + const hooks = new Hooks(); + const hookCallback = jest.fn(); + const plugin = new TapAllPlugin(hookCallback); + + plugin.install(hooks); + + Object.values(AST.ASTType).forEach((astType) => { + hooks[astType].call(undefined as never); + }); + + expect(hookCallback).toHaveBeenCalledTimes(Object.keys(AST.ASTType).length); + }); +}); diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json new file mode 100644 index 00000000..ddd4d566 --- /dev/null +++ b/packages/@postdfm/plugin/package.json @@ -0,0 +1,31 @@ +{ + "name": "@postdfm/plugin", + "version": "5.0.6", + "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "compile": "tsc --listEmittedFiles", + "docs": "typedoc --options typedoc.config.js" + }, + "author": "SpiltCoffee", + "license": "MIT", + "bugs": { + "url": "https://github.com/spiltcoffee/postdfm/issues" + }, + "homepage": "https://github.com/spiltcoffee/postdfm#readme", + "dependencies": { + "@postdfm/ast": "^5.0.6", + "tapable": "^2.2.0" + }, + "files": [ + "/dist", + "README.md" + ], + "engines": { + "node": ">=8.3.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/@postdfm/plugin/src/hooks.ts b/packages/@postdfm/plugin/src/hooks.ts new file mode 100644 index 00000000..4db86b56 --- /dev/null +++ b/packages/@postdfm/plugin/src/hooks.ts @@ -0,0 +1,126 @@ +import * as AST from "@postdfm/ast"; +import { MultiHook, SyncWaterfallHook } from "tapable"; + +export class Hooks { + [AST.ASTType.String]: SyncWaterfallHook; + [AST.ASTType.ControlString]: SyncWaterfallHook; + [AST.ASTType.LiteralString]: SyncWaterfallHook; + [AST.ASTType.BinaryString]: SyncWaterfallHook; + [AST.ASTType.Integer]: SyncWaterfallHook; + [AST.ASTType.HexCode]: SyncWaterfallHook; + [AST.ASTType.Double]: SyncWaterfallHook; + [AST.ASTType.Single]: SyncWaterfallHook; + [AST.ASTType.Currency]: SyncWaterfallHook; + [AST.ASTType.DateTime]: SyncWaterfallHook; + [AST.ASTType.Boolean]: SyncWaterfallHook; + [AST.ASTType.Identifier]: SyncWaterfallHook; + [AST.ASTType.Item]: SyncWaterfallHook; + [AST.ASTType.VariantList]: SyncWaterfallHook; + [AST.ASTType.BinaryStringList]: SyncWaterfallHook; + [AST.ASTType.IdentifierList]: SyncWaterfallHook; + [AST.ASTType.ItemList]: SyncWaterfallHook; + [AST.ASTType.Property]: SyncWaterfallHook; + [AST.ASTType.Object]: SyncWaterfallHook; + [AST.ASTType.Root]: SyncWaterfallHook; + all: MultiHook; + + constructor() { + this[AST.ASTType.String] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.String + ); + + this[AST.ASTType.ControlString] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.ControlString + ); + + this[AST.ASTType.LiteralString] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.LiteralString + ); + + this[AST.ASTType.BinaryString] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.BinaryString + ); + + this[AST.ASTType.Integer] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Integer + ); + + this[AST.ASTType.HexCode] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.HexCode + ); + + this[AST.ASTType.Double] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Double + ); + + this[AST.ASTType.Single] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Single + ); + + this[AST.ASTType.Currency] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Currency + ); + + this[AST.ASTType.DateTime] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.DateTime + ); + + this[AST.ASTType.Boolean] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Boolean + ); + + this[AST.ASTType.Identifier] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Identifier + ); + + this[AST.ASTType.Item] = new SyncWaterfallHook(["ast"], AST.ASTType.Item); + + this[AST.ASTType.VariantList] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.VariantList + ); + + this[AST.ASTType.BinaryStringList] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.BinaryStringList + ); + + this[AST.ASTType.IdentifierList] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.IdentifierList + ); + + this[AST.ASTType.ItemList] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.ItemList + ); + + this[AST.ASTType.Property] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Property + ); + + this[AST.ASTType.Object] = new SyncWaterfallHook( + ["ast"], + AST.ASTType.Object + ); + + this[AST.ASTType.Root] = new SyncWaterfallHook(["ast"], AST.ASTType.Root); + + this.all = new MultiHook( + Object.values(AST.ASTType).map((astType) => this[astType]) + ); + } +} diff --git a/packages/@postdfm/plugin/src/index.ts b/packages/@postdfm/plugin/src/index.ts new file mode 100644 index 00000000..a1885262 --- /dev/null +++ b/packages/@postdfm/plugin/src/index.ts @@ -0,0 +1,2 @@ +export { Hooks } from "./hooks"; +export { Plugin } from "./plugin"; diff --git a/packages/@postdfm/plugin/src/plugin.ts b/packages/@postdfm/plugin/src/plugin.ts new file mode 100644 index 00000000..7cb2877f --- /dev/null +++ b/packages/@postdfm/plugin/src/plugin.ts @@ -0,0 +1,5 @@ +import type { Hooks } from "./hooks"; + +export abstract class Plugin { + abstract install(hooks: Hooks): void; +} diff --git a/packages/@postdfm/plugin/tsconfig.json b/packages/@postdfm/plugin/tsconfig.json new file mode 100644 index 00000000..b05c8f74 --- /dev/null +++ b/packages/@postdfm/plugin/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src/**/*"] +} diff --git a/packages/@postdfm/plugin/typedoc.config.js b/packages/@postdfm/plugin/typedoc.config.js new file mode 100644 index 00000000..60d6b801 --- /dev/null +++ b/packages/@postdfm/plugin/typedoc.config.js @@ -0,0 +1,3 @@ +module.exports = require("../../../typedoc")({ + out: "@postdfm/plugin", +}); diff --git a/yarn.lock b/yarn.lock index 1e7f2d76..b6af92a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9220,6 +9220,11 @@ table@^6.0.4: slice-ansi "^4.0.0" string-width "^4.2.0" +tapable@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.0.tgz#5c373d281d9c672848213d0e037d1c4165ab426b" + integrity sha512-FBk4IesMV1rBxX2tfiK8RAmogtWn53puLOQlvO8XuwlgxcYbP4mVPS9Ph4aeamSyyVjOl24aYWAuc8U5kCVwMw== + tar-stream@^2.1.0, tar-stream@^2.1.2: version "2.1.4" resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.1.4.tgz#c4fb1a11eb0da29b893a5b25476397ba2d053bfa" From 0ca51793682739af3db726535055f3231ecae4d5 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:47:15 +1100 Subject: [PATCH 09/26] feat(@postdfm/transform): added @postdfm/transform Added @postdfm/transform fix #112 --- packages/@postdfm/transform/.eslintrc.js | 1 + packages/@postdfm/transform/README.md | 12 ++ .../transform/__test__/broken/index.test.ts | 28 +++ .../transform/__test__/fixtures/index.test.ts | 40 +++++ packages/@postdfm/transform/package.json | 31 ++++ packages/@postdfm/transform/src/index.ts | 1 + .../@postdfm/transform/src/transformer.ts | 169 ++++++++++++++++++ packages/@postdfm/transform/tsconfig.json | 7 + packages/@postdfm/transform/typedoc.config.js | 3 + 9 files changed, 292 insertions(+) create mode 100644 packages/@postdfm/transform/.eslintrc.js create mode 100644 packages/@postdfm/transform/README.md create mode 100644 packages/@postdfm/transform/__test__/broken/index.test.ts create mode 100644 packages/@postdfm/transform/__test__/fixtures/index.test.ts create mode 100644 packages/@postdfm/transform/package.json create mode 100644 packages/@postdfm/transform/src/index.ts create mode 100644 packages/@postdfm/transform/src/transformer.ts create mode 100644 packages/@postdfm/transform/tsconfig.json create mode 100644 packages/@postdfm/transform/typedoc.config.js diff --git a/packages/@postdfm/transform/.eslintrc.js b/packages/@postdfm/transform/.eslintrc.js new file mode 100644 index 00000000..dad6750a --- /dev/null +++ b/packages/@postdfm/transform/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require("../../../eslint.config.js")(true); diff --git a/packages/@postdfm/transform/README.md b/packages/@postdfm/transform/README.md new file mode 100644 index 00000000..c20f01a7 --- /dev/null +++ b/packages/@postdfm/transform/README.md @@ -0,0 +1,12 @@ +# @postdfm/transform + +[![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/transform/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/transform/package.json) + +Sub-package for `postdfm`. + +Provides functionality for iterating a `@postdfm/ast` Abstract Syntax Tree via Hooks (using Webpack's Tapable package). + +See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/transform/). diff --git a/packages/@postdfm/transform/__test__/broken/index.test.ts b/packages/@postdfm/transform/__test__/broken/index.test.ts new file mode 100644 index 00000000..ca3d2b33 --- /dev/null +++ b/packages/@postdfm/transform/__test__/broken/index.test.ts @@ -0,0 +1,28 @@ +import { ASTNode, ASTType } from "@postdfm/ast"; +import { Transformer } from "../../src"; + +describe("transform", () => { + test("broken AST throws error", () => { + const ast = ({ + raws: {}, + astType: "broken", + } as unknown) as ASTNode; + + const transformer = new Transformer([]); + + expect(() => transformer.transform(ast)).toThrow( + "Cannot generically transform astType broken" + ); + }); + + test("empty AST root does not throw error", () => { + const ast = { + raws: {}, + astType: ASTType.Root, + }; + + const transformer = new Transformer([]); + + expect(() => transformer.transform(ast)).not.toThrow(); + }); +}); diff --git a/packages/@postdfm/transform/__test__/fixtures/index.test.ts b/packages/@postdfm/transform/__test__/fixtures/index.test.ts new file mode 100644 index 00000000..14100078 --- /dev/null +++ b/packages/@postdfm/transform/__test__/fixtures/index.test.ts @@ -0,0 +1,40 @@ +import * as fs from "fs"; +import * as path from "path"; +import * as AST from "@postdfm/ast"; +import { Plugin } from "@postdfm/plugin"; +import { Transformer } from "../../src"; + +const rootFixturesDir = path.resolve("__test__", "__fixtures__"); +const transformFixturesDir = path.join(rootFixturesDir, "transform"); + +interface ReferencedPlugin { + new (): Plugin; +} + +describe("transform", () => { + describe("transform fixtures", () => { + const fixtures = fs.readdirSync(transformFixturesDir); + fixtures.forEach((fixture) => { + const fixtureDir = path.join(transformFixturesDir, fixture); + + const cisAst = JSON.parse( + fs.readFileSync(path.join(fixtureDir, "cis.json"), "utf-8") + ) as AST.ASTNode; + + const transAst = JSON.parse( + fs.readFileSync(path.join(fixtureDir, "trans.json"), "utf-8") + ) as AST.ASTNode; + + const plugins = [ + // eslint-disable-next-line @typescript-eslint/no-var-requires + new (require(path.join(fixtureDir, "plugin.js")) as ReferencedPlugin)(), + ]; + + const transformer = new Transformer(plugins); + + test(`${fixture}`, () => { + expect(transformer.transform(cisAst)).toEqual(transAst); + }); + }); + }); +}); diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json new file mode 100644 index 00000000..c664062c --- /dev/null +++ b/packages/@postdfm/transform/package.json @@ -0,0 +1,31 @@ +{ + "name": "@postdfm/transform", + "version": "5.0.6", + "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "compile": "tsc --listEmittedFiles", + "docs": "typedoc --options typedoc.config.js" + }, + "author": "SpiltCoffee", + "license": "MIT", + "bugs": { + "url": "https://github.com/spiltcoffee/postdfm/issues" + }, + "homepage": "https://github.com/spiltcoffee/postdfm#readme", + "dependencies": { + "@postdfm/ast": "^5.0.6", + "@postdfm/plugin": "^5.0.6" + }, + "files": [ + "/dist", + "README.md" + ], + "engines": { + "node": ">=8.3.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/@postdfm/transform/src/index.ts b/packages/@postdfm/transform/src/index.ts new file mode 100644 index 00000000..34193be8 --- /dev/null +++ b/packages/@postdfm/transform/src/index.ts @@ -0,0 +1 @@ +export { Transformer } from "./transformer"; diff --git a/packages/@postdfm/transform/src/transformer.ts b/packages/@postdfm/transform/src/transformer.ts new file mode 100644 index 00000000..9960e8c7 --- /dev/null +++ b/packages/@postdfm/transform/src/transformer.ts @@ -0,0 +1,169 @@ +import * as AST from "@postdfm/ast"; +import { AnyList } from "@postdfm/ast/dist/list/anyList"; +import { VariantValue } from "@postdfm/ast/dist/value/variantValue"; +import { StringValuePart } from "@postdfm/ast/dist/value/stringValuePart"; +import { Plugin, Hooks } from "@postdfm/plugin"; + +export class Transformer { + hooks: Hooks; + parents: AST.ASTNode[]; + + constructor(plugins: Plugin[]) { + this.hooks = new Hooks(); + plugins.forEach((plugin) => plugin.install(this.hooks)); + } + + transform(ast: AST.ASTNode): AST.ASTNode { + switch (ast.astType) { + case AST.ASTType.String: + return this.transformString(ast as AST.StringValue); + case AST.ASTType.ControlString: + return this.transformControlString(ast as AST.ControlString); + case AST.ASTType.LiteralString: + return this.transformLiteralString(ast as AST.LiteralString); + case AST.ASTType.Integer: + return this.transformInteger(ast as AST.IntegerValue); + case AST.ASTType.HexCode: + return this.transformHexCode(ast as AST.HexCodeValue); + case AST.ASTType.Double: + return this.transformDouble(ast as AST.DoubleValue); + case AST.ASTType.Single: + return this.transformSingle(ast as AST.SingleValue); + case AST.ASTType.Currency: + return this.transformCurrency(ast as AST.CurrencyValue); + case AST.ASTType.DateTime: + return this.transformDateTime(ast as AST.DateTimeValue); + case AST.ASTType.Boolean: + return this.transformBoolean(ast as AST.BooleanValue); + case AST.ASTType.Identifier: + return this.transformIdentifier(ast as AST.IdentifierValue); + case AST.ASTType.VariantList: + return this.transformVariantList(ast as AST.VariantList); + case AST.ASTType.BinaryStringList: + return this.transformBinaryStringList(ast as AST.BinaryStringList); + case AST.ASTType.IdentifierList: + return this.transformIdentifierList(ast as AST.IdentifierList); + case AST.ASTType.ItemList: + return this.transformItemList(ast as AST.ItemList); + case AST.ASTType.Root: + return this.transformRoot(ast as AST.Root); + default: + throw Error(`Cannot generically transform astType ${ast.astType}`); + } + } + + private transformString(ast: AST.StringValue): AST.StringValue { + ast = this.hooks[AST.ASTType.String].call(ast); + ast.value = ast.value.map((str) => this.transform(str) as StringValuePart); + return ast; + } + + private transformControlString(ast: AST.ControlString): AST.ControlString { + return this.hooks[AST.ASTType.ControlString].call(ast); + } + + private transformLiteralString(ast: AST.LiteralString): AST.LiteralString { + return this.hooks[AST.ASTType.LiteralString].call(ast); + } + + private transformBinaryString( + ast: AST.BinaryStringValue + ): AST.BinaryStringValue { + return this.hooks[AST.ASTType.BinaryString].call(ast); + } + + private transformInteger(ast: AST.IntegerValue): AST.IntegerValue { + return this.hooks[AST.ASTType.Integer].call(ast); + } + + private transformHexCode(ast: AST.HexCodeValue): AST.HexCodeValue { + return this.hooks[AST.ASTType.HexCode].call(ast); + } + + private transformDouble(ast: AST.DoubleValue): AST.DoubleValue { + return this.hooks[AST.ASTType.Double].call(ast); + } + + private transformSingle(ast: AST.SingleValue): AST.SingleValue { + return this.hooks[AST.ASTType.Single].call(ast); + } + + private transformCurrency(ast: AST.CurrencyValue): AST.CurrencyValue { + return this.hooks[AST.ASTType.Currency].call(ast); + } + + private transformDateTime(ast: AST.DateTimeValue): AST.DateTimeValue { + return this.hooks[AST.ASTType.DateTime].call(ast); + } + + private transformBoolean(ast: AST.BooleanValue): AST.BooleanValue { + return this.hooks[AST.ASTType.Boolean].call(ast); + } + + private transformIdentifier(ast: AST.IdentifierValue): AST.IdentifierValue { + return this.hooks[AST.ASTType.Identifier].call(ast); + } + + private transformItem(ast: AST.Item): AST.Item { + ast = this.hooks[AST.ASTType.Item].call(ast); + ast.properties = ast.properties.map((property) => + this.transformProperty(property) + ); + return ast; + } + + private transformVariantList(ast: AST.VariantList): AST.VariantList { + ast = this.hooks[AST.ASTType.VariantList].call(ast); + ast.values = ast.values.map( + (variant) => this.transform(variant) as VariantValue + ); + return ast; + } + + private transformBinaryStringList( + ast: AST.BinaryStringList + ): AST.BinaryStringList { + ast = this.hooks[AST.ASTType.BinaryStringList].call(ast); + ast.values = ast.values.map((binaryString) => + this.transformBinaryString(binaryString) + ); + return ast; + } + + private transformIdentifierList(ast: AST.IdentifierList): AST.IdentifierList { + ast = this.hooks[AST.ASTType.IdentifierList].call(ast); + ast.values = ast.values.map((identifier) => + this.transformIdentifier(identifier) + ); + return ast; + } + + private transformItemList(ast: AST.ItemList): AST.ItemList { + ast = this.hooks[AST.ASTType.ItemList].call(ast); + ast.values = ast.values.map((item) => this.transformItem(item)); + return ast; + } + + private transformProperty(ast: AST.Property): AST.Property { + ast = this.hooks[AST.ASTType.Property].call(ast); + ast.value = this.transform(ast.value) as VariantValue | AnyList; + return ast; + } + + private transformObject(ast: AST.DObject): AST.DObject { + ast = this.hooks[AST.ASTType.Object].call(ast); + ast.properties = ast.properties.map((property) => + this.transformProperty(property) + ); + ast.children = ast.children.map((child) => this.transformObject(child)); + return ast; + } + + private transformRoot(ast: AST.Root): AST.Root { + ast = this.hooks[AST.ASTType.Root].call(ast); + if (ast.child) { + ast.child = this.transformObject(ast.child); + } + return ast; + } +} diff --git a/packages/@postdfm/transform/tsconfig.json b/packages/@postdfm/transform/tsconfig.json new file mode 100644 index 00000000..b05c8f74 --- /dev/null +++ b/packages/@postdfm/transform/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src/**/*"] +} diff --git a/packages/@postdfm/transform/typedoc.config.js b/packages/@postdfm/transform/typedoc.config.js new file mode 100644 index 00000000..49c636fc --- /dev/null +++ b/packages/@postdfm/transform/typedoc.config.js @@ -0,0 +1,3 @@ +module.exports = require("../../../typedoc")({ + out: "@postdfm/transform", +}); From 319683548502b429a4d809e6daed708f2dbe6684 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:48:15 +1100 Subject: [PATCH 10/26] ci: add @postdfm/plugin and @postdfm/transform to circle ci pipelines --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e83ed0d7..60f0dd05 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,6 +49,8 @@ jobs: - ./@postdfm/ast2dfm/dist - ./@postdfm/dfm2ast/dist - ./@postdfm/dfm2ast/src + - ./@postdfm/plugin/dist + - ./@postdfm/transform/dist lint: executor: node-executor @@ -138,6 +140,10 @@ jobs: path: ~/repo/packages/@postdfm/ast2dfm/package.json - store_artifacts: path: ~/repo/packages/@postdfm/dfm2ast/package.json + - store_artifacts: + path: ~/repo/packages/@postdfm/plugin/package.json + - store_artifacts: + path: ~/repo/packages/@postdfm/transform/package.json workflows: version: 2 From 04d575767ff8d6003139e99a7e4e497d77eca89b Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:50:02 +1100 Subject: [PATCH 11/26] feat(postdfm): update postdfm to use @postdfm/plugin and @postdfm/transform BREAKING CHANGE: postdfm no longer accepts the transformer option. Instead, postdfm will accept plugins that extend the class available in the new @postdfm/transform package. --- packages/@postdfm/dfm2ast/src/index.ts | 1 + packages/postdfm/package.json | 4 +- packages/postdfm/src/index.ts | 51 +++++++++++++++----------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/packages/@postdfm/dfm2ast/src/index.ts b/packages/@postdfm/dfm2ast/src/index.ts index b68b9245..e2acef88 100644 --- a/packages/@postdfm/dfm2ast/src/index.ts +++ b/packages/@postdfm/dfm2ast/src/index.ts @@ -10,6 +10,7 @@ function parse(dfm: string): Root { throw new Error("Unexpected End Of Input"); } + /* istanbul ignore next */ if (parser.results.length > 1) { throw new Error( `Ambiguous Grammar: ${parser.results.length} Results Found\n\n` + diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index ef92cc5e..2daca889 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -27,7 +27,9 @@ "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { "@postdfm/ast2dfm": "^5.0.6", - "@postdfm/dfm2ast": "^5.0.6" + "@postdfm/dfm2ast": "^5.0.6", + "@postdfm/plugin": "^5.0.6", + "@postdfm/transform": "^5.0.6" }, "files": [ "dist/", diff --git a/packages/postdfm/src/index.ts b/packages/postdfm/src/index.ts index 88b5a32f..0de47e9a 100644 --- a/packages/postdfm/src/index.ts +++ b/packages/postdfm/src/index.ts @@ -1,23 +1,27 @@ import * as AST from "@postdfm/ast"; +import { Plugin } from "@postdfm/plugin"; import { stringify } from "@postdfm/ast2dfm"; +import { Transformer } from "@postdfm/transform"; import { parse } from "@postdfm/dfm2ast"; interface InternalRunnerOptions { parser: Parser; stringifier: Stringifier; - transformers: Transformer[]; + plugins: Plugin[]; +} + +interface ReferencedPlugin { + new (): Plugin; } export interface RunnerOptions { parser?: Parser | string; stringifier?: Stringifier | string; - transformers?: Array; + plugins?: Array; } export type Parser = (dfm: string) => AST.Root; -export type Transformer = (ast: AST.Root) => AST.Root; - export type Stringifier = (ast: AST.Root) => string; export interface ProcessingOptions { @@ -26,9 +30,12 @@ export interface ProcessingOptions { export class Runner { private options: InternalRunnerOptions; + private transformer: Transformer; constructor(options: InternalRunnerOptions) { this.options = options; + + this.transformer = new Transformer(this.options.plugins); } public processSync( @@ -50,18 +57,18 @@ export class Runner { } } + /* istanbul ignore next */ if (!ast) { throw new Error( - "Somehow, `ast` is null??\n\n" + + `Somehow, \`ast\` is falsy?? (type: ${typeof ast}, value: ${ + ast as string + })\n\n` + " This probably isn't your fault. Please consider raising an " + "issue with a reproducable case at github.com/spiltcoffee/postdfm" ); } - const transformed = this.options.transformers.reduce( - (currAst, transformer) => transformer(currAst), - ast - ); + const transformed = this.transformer.transform(ast); return this.options.stringifier(transformed); } @@ -80,7 +87,7 @@ export default function postdfm(options?: RunnerOptions): Runner { const internalOptions: InternalRunnerOptions = { parser: parse, stringifier: stringify, - transformers: [], + plugins: [], }; if (options) { @@ -106,27 +113,29 @@ export default function postdfm(options?: RunnerOptions): Runner { } } - if (options.transformers) { - if (!Array.isArray(options.transformers)) { + if (options.plugins) { + if (!Array.isArray(options.plugins)) { throw new Error( - "transformers must be an array of strings and/or functions" + "plugins must be an array of strings, functions and/or objects" ); } - options.transformers.forEach((transformer) => { - let internalTransformer: Transformer; - if (typeof transformer === "string") { + options.plugins.forEach((plugin) => { + let internalPlugin: Plugin; + if (typeof plugin === "string") { // eslint-disable-next-line @typescript-eslint/no-var-requires - internalTransformer = require(transformer) as Transformer; - } else if (typeof transformer === "function") { - internalTransformer = transformer; + internalPlugin = new (require(plugin) as ReferencedPlugin)(); + } else if (typeof plugin === "function") { + internalPlugin = new (plugin as ReferencedPlugin)(); + } else if (typeof plugin === "object") { + internalPlugin = plugin; } else { throw new Error( - "transformers must be an array of strings and/or functions" + "plugins must be an array of strings, functions and/or objects" ); } - internalOptions.transformers.push(internalTransformer); + internalOptions.plugins.push(internalPlugin); }); } } From 74e18c4073309c3bc112614b9f297a6a0ae8f505 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 14:50:33 +1100 Subject: [PATCH 12/26] test: update tests --- .../__fixtures__/transform/everything/cis.dfm | 69 ++ .../transform/everything/cis.json | 820 ++++++++++++++++++ .../transform/everything/plugin.js | 137 +++ .../transform/everything/trans.dfm | 69 ++ .../transform/everything/trans.json | 820 ++++++++++++++++++ .../transform/hello-world/cis.json | 37 + .../transform/hello-world/plugin.js | 11 + .../transform/hello-world/trans.json | 37 + .../transform/hello-world/transformer.js | 26 - .../postdfm/__test__/fixtures/index.test.ts | 14 +- .../postdfm/__test__/options/index.test.ts | 55 +- packages/postdfm/__test__/options/plugin.js | 7 + .../postdfm/__test__/options/transformer.js | 1 - 13 files changed, 2045 insertions(+), 58 deletions(-) create mode 100644 __test__/__fixtures__/transform/everything/cis.dfm create mode 100644 __test__/__fixtures__/transform/everything/cis.json create mode 100644 __test__/__fixtures__/transform/everything/plugin.js create mode 100644 __test__/__fixtures__/transform/everything/trans.dfm create mode 100644 __test__/__fixtures__/transform/everything/trans.json create mode 100644 __test__/__fixtures__/transform/hello-world/cis.json create mode 100644 __test__/__fixtures__/transform/hello-world/plugin.js create mode 100644 __test__/__fixtures__/transform/hello-world/trans.json delete mode 100644 __test__/__fixtures__/transform/hello-world/transformer.js create mode 100644 packages/postdfm/__test__/options/plugin.js delete mode 100644 packages/postdfm/__test__/options/transformer.js diff --git a/__test__/__fixtures__/transform/everything/cis.dfm b/__test__/__fixtures__/transform/everything/cis.dfm new file mode 100644 index 00000000..fa053e51 --- /dev/null +++ b/__test__/__fixtures__/transform/everything/cis.dfm @@ -0,0 +1,69 @@ +object Form1: TForm1 + Left = 192 + Font.Name = 'MS Sans Serif' + Font.Style = [] + Border.Bottom.Style = bdSolid + object Image1: TImage + Picture.Data = { + 07544269746D617036550000424D365500000000000036000000280000005500 + 000055000000010018000000000000550000C40E0000C40E0000000000000000 + } + Picture.MoreData = {} + end + inherited ListBox1: TListBox [2] + Items.Strings = + ( 'this is string.' + 'and another one...' + + 'and another one...' + + 'now with apostrophe '''#13#10'how fancy' + ) + Items.MoreStrings = () + end + object DBGrid1: TDBGrid + Options = [dgTitles, dg_Indicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit] + MoreOptions = [] + Columns = < + item + Expanded = False + Visible = True + end + item + end + item + Expanded = False + Visible = True + end> + MoreColumns = <> + end + inline Edit1: TEdit + MaxLength = 6e20 + MinLength = -20e1 + SomeOtherLength = 45.333e20 + Color = $FF0000 + BackgroundColorStreamer = ( + 255 + 255 + 255 + True) + end + object MyContainer: TContainer + Cost = 32.5c + MinCost = 0c + Multiplier = 12.5s + Date = 47000.1d + end + object Edit2: TEdit + Value = + 'Some ''multi'' line ' + + 'string'#13#10 + + #37'hello'#45'world' + end + object SubForm: TForm2 + inline SubEdit: TEdit + Value = '' + EditType = TEdit.TypeEnum.PASSWORD + end + end + object Nothing: _TNothing + end +end diff --git a/__test__/__fixtures__/transform/everything/cis.json b/__test__/__fixtures__/transform/everything/cis.json new file mode 100644 index 00000000..5d4b34ef --- /dev/null +++ b/__test__/__fixtures__/transform/everything/cis.json @@ -0,0 +1,820 @@ +{ + "astType": "root", + "child": { + "astType": "object", + "kind": "object", + "name": "Form1", + "type": "TForm1", + "properties": [ + { + "astType": "property", + "name": "Left", + "value": { + "astType": "integer", + "value": "192" + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "Font.Name", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "MS Sans Serif" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Font.Style", + "value": { + "astType": "identifierList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Border.Bottom.Style", + "value": { + "astType": "identifier", + "value": "bdSolid" + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [ + { + "astType": "object", + "kind": "object", + "name": "Image1", + "type": "TImage", + "properties": [ + { + "astType": "property", + "name": "Picture.Data", + "value": { + "astType": "binaryStringList", + "values": [ + { + "astType": "binaryString", + "value": "07544269746D617036550000424D365500000000000036000000280000005500" + }, + { + "astType": "binaryString", + "value": "000055000000010018000000000000550000C40E0000C40E0000000000000000", + "raws": { + "before": "\r\n " + } + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "\r\n " + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "Picture.MoreData", + "value": { + "astType": "binaryStringList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n " + } + }, + { + "astType": "object", + "kind": "inherited", + "name": "ListBox1", + "type": "TListBox", + "order": "2", + "properties": [ + { + "astType": "property", + "name": "Items.Strings", + "value": { + "astType": "variantList", + "values": [ + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "this is string." + } + ] + }, + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "and another one..." + }, + { + "astType": "literalString", + "value": "and another one...", + "raws": { + "before": "\r\n + " + } + }, + { + "astType": "literalString", + "value": "now with apostrophe '", + "raws": { + "before": "\r\n + " + } + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "literalString", + "value": "how fancy" + } + ], + "raws": { + "before": "\r\n " + } + } + ], + "raws": { + "afterOpen": " ", + "beforeClose": "\r\n " + } + }, + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + } + }, + { + "astType": "property", + "name": "Items.MoreStrings", + "value": { + "astType": "variantList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "afterType": " ", + "beforeOrder": "", + "afterOrder": "", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "DBGrid1", + "type": "TDBGrid", + "properties": [ + { + "astType": "property", + "name": "Options", + "value": { + "astType": "identifierList", + "values": [ + { + "astType": "identifier", + "value": "dgTitles", + "raws": { + "after": "" + } + }, + { + "astType": "identifier", + "value": "dg_Indicator", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgColumnResize", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgColLines", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgRowLines", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgTabs", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgRowSelect", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgConfirmDelete", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "dgCancelOnExit", + "raws": { + "before": " " + } + } + ], + "raws": { + "afterOpen": "", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "MoreOptions", + "value": { + "astType": "identifierList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Columns", + "value": { + "astType": "itemList", + "values": [ + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "value": { + "astType": "boolean", + "value": false + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "Visible", + "value": { + "astType": "boolean", + "value": true + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n " + } + }, + { + "astType": "item", + "properties": [], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "Expanded", + "value": { + "astType": "boolean", + "value": false + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "Visible", + "value": { + "astType": "boolean", + "value": true + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "MoreColumns", + "value": { + "astType": "itemList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "inline", + "name": "Edit1", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "MaxLength", + "value": { + "astType": "double", + "value": { + "integer": "6", + "exponent": "20" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "MinLength", + "value": { + "astType": "double", + "value": { + "integer": "-20", + "exponent": "1" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "SomeOtherLength", + "value": { + "astType": "double", + "value": { + "integer": "45", + "fraction": "333", + "exponent": "20" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Color", + "value": { + "astType": "hexCode", + "value": "FF0000" + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "BackgroundColorStreamer", + "value": { + "astType": "variantList", + "values": [ + { + "astType": "integer", + "value": "255" + }, + { + "astType": "integer", + "value": "255", + "raws": { + "before": "\r\n " + } + }, + { + "astType": "integer", + "value": "255", + "raws": { + "before": "\r\n " + } + }, + { + "astType": "boolean", + "value": true, + "raws": { + "before": "\r\n " + } + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "MyContainer", + "type": "TContainer", + "properties": [ + { + "astType": "property", + "name": "Cost", + "value": { + "astType": "currency", + "value": { + "integer": "32", + "fraction": "5" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "MinCost", + "value": { + "astType": "currency", + "value": { "integer": "0" } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Multiplier", + "value": { + "astType": "single", + "value": { + "integer": "12", + "fraction": "5" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "Date", + "value": { + "astType": "dateTime", + "value": { + "integer": "47000", + "fraction": "1" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "Edit2", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "Value", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "Some 'multi' line " + }, + { + "astType": "literalString", + "value": "string", + "raws": { + "before": " +\r\n " + } + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "controlString", + "value": "%", + "raws": { + "before": " +\r\n " + } + }, + { + "astType": "literalString", + "value": "hello" + }, + { + "astType": "controlString", + "value": "-" + }, + { + "astType": "literalString", + "value": "world" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "SubForm", + "type": "TForm2", + "properties": [], + "children": [ + { + "astType": "object", + "kind": "inline", + "name": "SubEdit", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "Value", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "EditType", + "value": { + "astType": "identifier", + "value": "TEdit.TypeEnum.PASSWORD" + }, + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "Nothing", + "type": "_TNothing", + "properties": [], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n" + } + }, + "raws": { + "before": "", + "after": "\r\n" + } +} diff --git a/__test__/__fixtures__/transform/everything/plugin.js b/__test__/__fixtures__/transform/everything/plugin.js new file mode 100644 index 00000000..afe4e520 --- /dev/null +++ b/__test__/__fixtures__/transform/everything/plugin.js @@ -0,0 +1,137 @@ +// eslint-disable-next-line node/no-extraneous-require +const { Plugin } = require("@postdfm/plugin"); + +function reverseString(str) { + return str.split("").reverse().join(""); +} + +module.exports = class ReverseEverythingPlugin extends Plugin { + PLUGIN_NAME = "ReverseEverythingPlugin"; + + hookCallback; + + constructor(hookCallback) { + super(); + this.hookCallback = hookCallback || (() => {}); + } + + install(hooks) { + hooks.string.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = ast.value.reverse(); + return ast; + }); + + hooks.controlString.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = reverseString(ast.value); + return ast; + }); + + hooks.literalString.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = reverseString(ast.value); + return ast; + }); + + hooks.binaryString.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = reverseString(ast.value); + return ast; + }); + + hooks.integer.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = ((Number(ast.value) + 1) * -1).toString(); + return ast; + }); + + hooks.hexCode.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = reverseString(ast.value); + return ast; + }); + + hooks.double.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value.integer = ((Number(ast.value.integer) + 1) * -1).toString(); + return ast; + }); + + hooks.single.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value.integer = ((Number(ast.value.integer) + 1) * -1).toString(); + return ast; + }); + + hooks.currency.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value.integer = ((Number(ast.value.integer) + 1) * -1).toString(); + return ast; + }); + + hooks.dateTime.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value.integer = ((Number(ast.value.integer) + 1) * -1).toString(); + return ast; + }); + + hooks.boolean.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = !ast.value; + return ast; + }); + + hooks.identifier.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.value = reverseString(ast.value); + return ast; + }); + + hooks.item.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.properties = ast.properties.reverse(); + return ast; + }); + + hooks.variantList.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.values = ast.values.reverse(); + return ast; + }); + + hooks.binaryStringList.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.values = ast.values.reverse(); + return ast; + }); + + hooks.identifierList.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.values = ast.values.reverse(); + return ast; + }); + + hooks.itemList.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.values = ast.values.reverse(); + return ast; + }); + + hooks.property.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.name = reverseString(ast.name); + return ast; + }); + + hooks.object.tap(this.PLUGIN_NAME, (ast) => { + this.hookCallback(); + ast.name = reverseString(ast.name); + }); + + hooks.root.tap(this.PLUGIN_NAME, () => { + this.hookCallback(); + // nothing to reverse here + }); + } +}; diff --git a/__test__/__fixtures__/transform/everything/trans.dfm b/__test__/__fixtures__/transform/everything/trans.dfm new file mode 100644 index 00000000..9ba65bf0 --- /dev/null +++ b/__test__/__fixtures__/transform/everything/trans.dfm @@ -0,0 +1,69 @@ +object 1mroF: TForm1 + tfeL = -193 + emaN.tnoF = 'fireS snaS SM' + elytS.tnoF = [] + elytS.mottoB.redroB = diloSdb + object 1egamI: TImage + ataD.erutciP = { + + 0000000000000000E04C0000E04C000055000000000000810010000000550000005500000082000000630000000000005563D424000055630716D64796244570 + } + ataDeroM.erutciP = {} + end + inherited 1xoBtsiL: TListBox [2] + sgnirtS.smetI = + ( + 'ycnaf woh'#10#13 + + ''' ehportsopa htiw won' + + '...eno rehtona dna''...eno rehtona dna''.gnirts si siht' + ) + sgnirtSeroM.smetI = () + end + object 1dirGBD: TDBGrid + snoitpO = [ tixEnOlecnaCgd, eteleDmrifnoCgd, tceleSwoRgd, sbaTgd, seniLwoRgd, seniLloCgd, eziseRnmuloCgd, rotacidnI_gd,seltiTgd] + snoitpOeroM = [] + snmuloC = < + + item + + elbisiV = FalsedednapxE = True + end + item + enditem + + elbisiV = FalsedednapxE = True + end> + snmuloCeroM = <> + end + inline 1tidE: TEdit + htgneLxaM = -7e20 + htgneLniM = 19e1 + htgneLrehtOemoS = -46.333e20 + roloC = $0000FF + remaertSroloCdnuorgkcaB = ( + + False + -256 + -256-256) + end + object reniatnoCyM: TContainer + tsoC = -33.5c + tsoCniM = -1c + reilpitluM = -13.5s + etaD = -47001.1d + end + object 2tidE: TEdit + eulaV = + 'dlrow'#45'olleh' + + #37#10#13 + + 'gnirts'' enil ''itlum'' emoS' + end + object mroFbuS: TForm2 + inline tidEbuS: TEdit + eulaV = '' + epyTtidE = DROWSSAP.munEepyT.tidET + end + end + object gnihtoN: _TNothing + end +end diff --git a/__test__/__fixtures__/transform/everything/trans.json b/__test__/__fixtures__/transform/everything/trans.json new file mode 100644 index 00000000..22e9b947 --- /dev/null +++ b/__test__/__fixtures__/transform/everything/trans.json @@ -0,0 +1,820 @@ +{ + "astType": "root", + "child": { + "astType": "object", + "kind": "object", + "name": "1mroF", + "type": "TForm1", + "properties": [ + { + "astType": "property", + "name": "tfeL", + "value": { + "astType": "integer", + "value": "-193" + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "emaN.tnoF", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "fireS snaS SM" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "elytS.tnoF", + "value": { + "astType": "identifierList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "elytS.mottoB.redroB", + "value": { + "astType": "identifier", + "value": "diloSdb" + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [ + { + "astType": "object", + "kind": "object", + "name": "1egamI", + "type": "TImage", + "properties": [ + { + "astType": "property", + "name": "ataD.erutciP", + "value": { + "astType": "binaryStringList", + "values": [ + { + "astType": "binaryString", + "value": "0000000000000000E04C0000E04C000055000000000000810010000000550000", + "raws": { + "before": "\r\n " + } + }, + { + "astType": "binaryString", + "value": "005500000082000000630000000000005563D424000055630716D64796244570" + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "\r\n " + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "ataDeroM.erutciP", + "value": { + "astType": "binaryStringList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n " + } + }, + { + "astType": "object", + "kind": "inherited", + "name": "1xoBtsiL", + "type": "TListBox", + "order": "2", + "properties": [ + { + "astType": "property", + "name": "sgnirtS.smetI", + "value": { + "astType": "variantList", + "values": [ + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "ycnaf woh" + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "literalString", + "value": "' ehportsopa htiw won", + "raws": { + "before": "\r\n + " + } + }, + { + "astType": "literalString", + "value": "...eno rehtona dna", + "raws": { + "before": "\r\n + " + } + }, + { + "astType": "literalString", + "value": "...eno rehtona dna" + } + ], + "raws": { + "before": "\r\n " + } + }, + { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": ".gnirts si siht" + } + ] + } + ], + "raws": { + "afterOpen": " ", + "beforeClose": "\r\n " + } + }, + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + } + }, + { + "astType": "property", + "name": "sgnirtSeroM.smetI", + "value": { + "astType": "variantList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "afterType": " ", + "beforeOrder": "", + "afterOrder": "", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "1dirGBD", + "type": "TDBGrid", + "properties": [ + { + "astType": "property", + "name": "snoitpO", + "value": { + "astType": "identifierList", + "values": [ + { + "astType": "identifier", + "value": "tixEnOlecnaCgd", + "raws": { + "before": " " + } + }, + { + "astType": "identifier", + "value": "eteleDmrifnoCgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "tceleSwoRgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "sbaTgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "seniLwoRgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "seniLloCgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "eziseRnmuloCgd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "rotacidnI_gd", + "raws": { + "before": " ", + "after": "" + } + }, + { + "astType": "identifier", + "value": "seltiTgd", + "raws": { + "after": "" + } + } + ], + "raws": { + "afterOpen": "", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "snoitpOeroM", + "value": { + "astType": "identifierList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "snmuloC", + "value": { + "astType": "itemList", + "values": [ + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "elbisiV", + "value": { + "astType": "boolean", + "value": false + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "dednapxE", + "value": { + "astType": "boolean", + "value": true + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "item", + "properties": [], + "raws": { + "afterItem": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "item", + "properties": [ + { + "astType": "property", + "name": "elbisiV", + "value": { + "astType": "boolean", + "value": false + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "dednapxE", + "value": { + "astType": "boolean", + "value": true + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + } + ], + "raws": { + "afterItem": "\r\n ", + "beforeEnd": "\r\n " + } + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "snmuloCeroM", + "value": { + "astType": "itemList", + "values": [], + "raws": { + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "inline", + "name": "1tidE", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "htgneLxaM", + "value": { + "astType": "double", + "value": { + "integer": "-7", + "exponent": "20" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "htgneLniM", + "value": { + "astType": "double", + "value": { + "integer": "19", + "exponent": "1" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "htgneLrehtOemoS", + "value": { + "astType": "double", + "value": { + "integer": "-46", + "fraction": "333", + "exponent": "20" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "roloC", + "value": { + "astType": "hexCode", + "value": "0000FF" + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "remaertSroloCdnuorgkcaB", + "value": { + "astType": "variantList", + "values": [ + { + "astType": "boolean", + "value": false, + "raws": { + "before": "\r\n " + } + }, + { + "astType": "integer", + "value": "-256", + "raws": { + "before": "\r\n " + } + }, + { + "astType": "integer", + "value": "-256", + "raws": { + "before": "\r\n " + } + }, + { + "astType": "integer", + "value": "-256" + } + ], + "raws": { + "afterOpen": "\r\n ", + "beforeClose": "" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "reniatnoCyM", + "type": "TContainer", + "properties": [ + { + "astType": "property", + "name": "tsoC", + "value": { + "astType": "currency", + "value": { + "integer": "-33", + "fraction": "5" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "tsoCniM", + "value": { + "astType": "currency", + "value": { "integer": "-1" } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "reilpitluM", + "value": { + "astType": "single", + "value": { + "integer": "-13", + "fraction": "5" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + }, + { + "astType": "property", + "name": "etaD", + "value": { + "astType": "dateTime", + "value": { + "integer": "-47001", + "fraction": "1" + } + }, + "raws": { + "afterName": " ", + "beforeValue": " ", + "before": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "2tidE", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "eulaV", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "dlrow" + }, + { + "astType": "controlString", + "value": "-" + }, + { + "astType": "literalString", + "value": "olleh" + }, + { + "astType": "controlString", + "value": "%", + "raws": { + "before": " +\r\n " + } + }, + { + "astType": "controlString", + "value": "\n" + }, + { + "astType": "controlString", + "value": "\r" + }, + { + "astType": "literalString", + "value": "gnirts", + "raws": { + "before": " +\r\n " + } + }, + { + "astType": "literalString", + "value": " enil 'itlum' emoS" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": "\r\n " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "mroFbuS", + "type": "TForm2", + "properties": [], + "children": [ + { + "astType": "object", + "kind": "inline", + "name": "tidEbuS", + "type": "TEdit", + "properties": [ + { + "astType": "property", + "name": "eulaV", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + }, + { + "astType": "property", + "name": "epyTtidE", + "value": { + "astType": "identifier", + "value": "DROWSSAP.munEepyT.tidET" + }, + "raws": { + "afterName": " ", + "before": "\r\n ", + "beforeValue": " " + } + } + ], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "name": "gnihtoN", + "type": "_TNothing", + "properties": [], + "children": [], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + } + ], + "raws": { + "afterName": "", + "beforeType": " ", + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeChildren": "\r\n ", + "beforeEnd": "\r\n" + } + }, + "raws": { + "before": "", + "after": "\r\n" + } +} diff --git a/__test__/__fixtures__/transform/hello-world/cis.json b/__test__/__fixtures__/transform/hello-world/cis.json new file mode 100644 index 00000000..01d4c3ef --- /dev/null +++ b/__test__/__fixtures__/transform/hello-world/cis.json @@ -0,0 +1,37 @@ +{ + "astType": "root", + "child": { + "astType": "object", + "kind": "object", + "name": "Test", + "properties": [ + { + "astType": "property", + "name": "Hello", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "World" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + } + ], + "children": [], + "raws": { + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n" + } + }, + "raws": { + "before": "", + "after": "\r\n" + } +} diff --git a/__test__/__fixtures__/transform/hello-world/plugin.js b/__test__/__fixtures__/transform/hello-world/plugin.js new file mode 100644 index 00000000..8986740b --- /dev/null +++ b/__test__/__fixtures__/transform/hello-world/plugin.js @@ -0,0 +1,11 @@ +// eslint-disable-next-line node/no-extraneous-require +const { Plugin } = require("@postdfm/plugin"); + +module.exports = class HelloWorldPlugin extends Plugin { + install(hooks) { + hooks.property.tap("HelloWorldPlugin", (node) => { + node.name = node.name.split("").reverse().join(""); + return node; + }); + } +}; diff --git a/__test__/__fixtures__/transform/hello-world/trans.json b/__test__/__fixtures__/transform/hello-world/trans.json new file mode 100644 index 00000000..4a7f067f --- /dev/null +++ b/__test__/__fixtures__/transform/hello-world/trans.json @@ -0,0 +1,37 @@ +{ + "astType": "root", + "child": { + "astType": "object", + "kind": "object", + "name": "Test", + "properties": [ + { + "astType": "property", + "name": "olleH", + "value": { + "astType": "string", + "value": [ + { + "astType": "literalString", + "value": "World" + } + ] + }, + "raws": { + "afterName": " ", + "beforeValue": " " + } + } + ], + "children": [], + "raws": { + "beforeName": " ", + "beforeProperties": "\r\n ", + "beforeEnd": "\r\n" + } + }, + "raws": { + "before": "", + "after": "\r\n" + } +} diff --git a/__test__/__fixtures__/transform/hello-world/transformer.js b/__test__/__fixtures__/transform/hello-world/transformer.js deleted file mode 100644 index 51a3ef43..00000000 --- a/__test__/__fixtures__/transform/hello-world/transformer.js +++ /dev/null @@ -1,26 +0,0 @@ -function gatherObjects(object) { - return [].concat( - object, - object.children.map((child) => gatherObjects(child)) - ); -} - -function gatherProperties(object) { - const objects = gatherObjects(object); - - return objects.reduce((properties, object) => { - return [].concat(properties, object.properties); - }, []); -} - -function visitProperties(object, callback) { - gatherProperties(object).forEach((property) => callback(property)); -} - -module.exports = (ast) => { - visitProperties(ast.child, (property) => { - property.name = property.name.split("").reverse().join(""); - }); - - return ast; -}; diff --git a/packages/postdfm/__test__/fixtures/index.test.ts b/packages/postdfm/__test__/fixtures/index.test.ts index ade5756a..434a0702 100644 --- a/packages/postdfm/__test__/fixtures/index.test.ts +++ b/packages/postdfm/__test__/fixtures/index.test.ts @@ -1,20 +1,22 @@ import * as fs from "fs"; import * as path from "path"; import postdfm from "../../src"; -import { Root } from "@postdfm/ast"; +import { Plugin } from "@postdfm/plugin"; const rootFixturesDir = path.resolve("__test__", "__fixtures__"); const parseFixturesDir = path.join(rootFixturesDir, "parse"); const transformFixturesDir = path.join(rootFixturesDir, "transform"); -function noopTransform(ast: Root): Root { - return ast; +class NoopPlugin extends Plugin { + install(): void { + // do nothing + } } describe("postdfm", () => { describe("parse fixtures", () => { const runner = postdfm({ - transformers: [noopTransform], + plugins: [NoopPlugin], }); const fixtures = fs.readdirSync(parseFixturesDir); @@ -50,9 +52,9 @@ describe("postdfm", () => { path.join(fixtureDir, "trans.dfm"), "ascii" ); - const transformers = [require(path.join(fixtureDir, "transformer.js"))]; + const plugins = [require(path.join(fixtureDir, "plugin.js"))]; - const runner = postdfm({ transformers }); + const runner = postdfm({ plugins }); describe(`${fixture}`, () => { test("sync", () => { diff --git a/packages/postdfm/__test__/options/index.test.ts b/packages/postdfm/__test__/options/index.test.ts index ed9893a5..be5e0f5c 100644 --- a/packages/postdfm/__test__/options/index.test.ts +++ b/packages/postdfm/__test__/options/index.test.ts @@ -1,11 +1,13 @@ import { stringify } from "@postdfm/ast2dfm"; import { parse } from "@postdfm/dfm2ast"; import * as path from "path"; -import postdfm, { RunnerOptions, Transformer } from "../../src"; -import { Root } from "@postdfm/ast"; +import postdfm, { RunnerOptions } from "../../src"; +import { Plugin } from "@postdfm/plugin"; -function noopTransformer(ast: Root): Root { - return ast; +class NoopPlugin extends Plugin { + install(): void { + // do nothing + } } describe("postdfm", () => { @@ -13,42 +15,41 @@ describe("postdfm", () => { test("valid (normal)", () => { const parser = parse; const stringifier = stringify; - const transformers: Transformer[] = [noopTransformer]; + const plugins: Array = [ + NoopPlugin, + new NoopPlugin(), + ]; expect(() => postdfm()).not.toThrow(); - expect(() => postdfm()).not.toThrow(); + expect(() => postdfm({})).not.toThrow(); expect(() => postdfm({ parser })).not.toThrow(); expect(() => postdfm({ stringifier })).not.toThrow(); - expect(() => postdfm({ transformers })).not.toThrow(); + expect(() => postdfm({ plugins })).not.toThrow(); expect(() => postdfm({ parser, stringifier })).not.toThrow(); - expect(() => postdfm({ parser, transformers })).not.toThrow(); - expect(() => postdfm({ stringifier, transformers })).not.toThrow(); - expect(() => - postdfm({ parser, stringifier, transformers }) - ).not.toThrow(); + expect(() => postdfm({ parser, plugins })).not.toThrow(); + expect(() => postdfm({ stringifier, plugins })).not.toThrow(); + expect(() => postdfm({ parser, stringifier, plugins })).not.toThrow(); }); test("valid (using strings)", () => { const parser = "@postdfm/dfm2ast"; const stringifier = "@postdfm/ast2dfm"; - const transformers = [path.join(__dirname, "transformer.js")]; + const plugins = [path.join(__dirname, "plugin.js")]; expect(() => postdfm({ parser })).not.toThrow(); expect(() => postdfm({ stringifier })).not.toThrow(); - expect(() => postdfm({ transformers })).not.toThrow(); + expect(() => postdfm({ plugins })).not.toThrow(); expect(() => postdfm({ parser, stringifier })).not.toThrow(); - expect(() => postdfm({ parser, transformers })).not.toThrow(); - expect(() => postdfm({ stringifier, transformers })).not.toThrow(); - expect(() => - postdfm({ parser, stringifier, transformers }) - ).not.toThrow(); + expect(() => postdfm({ parser, plugins })).not.toThrow(); + expect(() => postdfm({ stringifier, plugins })).not.toThrow(); + expect(() => postdfm({ parser, stringifier, plugins })).not.toThrow(); }); test("invalid", () => { const parser = true; const stringifier = 5; - const transformer1 = {}; - const transformer2 = [5]; + const plugin1 = {}; + const plugin2 = [5]; expect(() => postdfm(({ parser } as unknown) as RunnerOptions)).toThrow( /parser must be a string or a function/ @@ -57,11 +58,15 @@ describe("postdfm", () => { postdfm(({ stringifier } as unknown) as RunnerOptions) ).toThrow(/stringifier must be a string or a function/); expect(() => - postdfm(({ transformers: transformer1 } as unknown) as RunnerOptions) - ).toThrow(/transformers must be an array of strings and\/or functions/); + postdfm(({ plugins: plugin1 } as unknown) as RunnerOptions) + ).toThrow( + /plugins must be an array of strings, functions and\/or objects/ + ); expect(() => - postdfm(({ transformers: transformer2 } as unknown) as RunnerOptions) - ).toThrow(/transformers must be an array of strings and\/or functions/); + postdfm(({ plugins: plugin2 } as unknown) as RunnerOptions) + ).toThrow( + /plugins must be an array of strings, functions and\/or objects/ + ); }); }); }); diff --git a/packages/postdfm/__test__/options/plugin.js b/packages/postdfm/__test__/options/plugin.js new file mode 100644 index 00000000..e5f91e5d --- /dev/null +++ b/packages/postdfm/__test__/options/plugin.js @@ -0,0 +1,7 @@ +const { Plugin } = require("@postdfm/plugin"); + +module.exports = class NoopPlugin extends Plugin { + install() { + // do nothing + } +}; diff --git a/packages/postdfm/__test__/options/transformer.js b/packages/postdfm/__test__/options/transformer.js deleted file mode 100644 index e48737e2..00000000 --- a/packages/postdfm/__test__/options/transformer.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = (ast) => ast; From 7d6e457daf83ccaca509ee546aaf1530c73d0871 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 25 Jan 2021 04:00:54 +0000 Subject: [PATCH 13/26] chore(release): 6.0.0-beta.1 [skip ci] # [6.0.0-beta.1](https://github.com/spiltcoffee/postdfm/compare/v5.0.6...v6.0.0-beta.1) (2021-01-25) ### Bug Fixes * set node minimum version to 8.3.0 ([9853a00](https://github.com/spiltcoffee/postdfm/commit/9853a00843d92075d851d7a7813a108ca2b467eb)) ### Features * **@postdfm/plugin:** added @postdfm/plugin ([ec48a72](https://github.com/spiltcoffee/postdfm/commit/ec48a7288815864a617144096cf900b8247f8584)), closes [#198](https://github.com/spiltcoffee/postdfm/issues/198) * **@postdfm/transform:** added @postdfm/transform ([0ca5179](https://github.com/spiltcoffee/postdfm/commit/0ca51793682739af3db726535055f3231ecae4d5)), closes [#112](https://github.com/spiltcoffee/postdfm/issues/112) * **postdfm:** update postdfm to use @postdfm/plugin and @postdfm/transform ([04d5757](https://github.com/spiltcoffee/postdfm/commit/04d575767ff8d6003139e99a7e4e497d77eca89b)) ### BREAKING CHANGES * **postdfm:** postdfm no longer accepts the transformer option. Instead, postdfm will accept plugins that extend the class available in the new @postdfm/transform package. * set node minimum version to 8.3.0 --- packages/@postdfm/ast/package.json | 2 +- packages/@postdfm/ast2dfm/package.json | 4 ++-- packages/@postdfm/dfm2ast/package.json | 4 ++-- packages/@postdfm/plugin/package.json | 4 ++-- packages/@postdfm/transform/package.json | 6 +++--- packages/postdfm/package.json | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index 5a1793fa..b0aa10aa 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Abstract Syntax Tree classes for postdfm", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index e1ff9a4a..0a2a5368 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast2dfm", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Convert DFM Abstract Syntax Trees to a Delphi Form file", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^5.0.6" + "@postdfm/ast": "^6.0.0-beta.1" }, "files": [ "/dist", diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index adad5099..40db523e 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/dfm2ast", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Convert Delphi Form files to an Abstract Syntax Tree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^5.0.6", + "@postdfm/ast": "^6.0.0-beta.1", "nearley": "^2.19.4" }, "files": [ diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index ddd4d566..e4a4cf66 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/plugin", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^5.0.6", + "@postdfm/ast": "^6.0.0-beta.1", "tapable": "^2.2.0" }, "files": [ diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index c664062c..f6b2344c 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/transform", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,8 +15,8 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^5.0.6", - "@postdfm/plugin": "^5.0.6" + "@postdfm/ast": "^6.0.0-beta.1", + "@postdfm/plugin": "^6.0.0-beta.1" }, "files": [ "/dist", diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index 2daca889..b02dae53 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -1,6 +1,6 @@ { "name": "postdfm", - "version": "5.0.6", + "version": "6.0.0-beta.1", "description": "Provides an API for easily transforming Delphi Forms", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast2dfm": "^5.0.6", - "@postdfm/dfm2ast": "^5.0.6", - "@postdfm/plugin": "^5.0.6", - "@postdfm/transform": "^5.0.6" + "@postdfm/ast2dfm": "^6.0.0-beta.1", + "@postdfm/dfm2ast": "^6.0.0-beta.1", + "@postdfm/plugin": "^6.0.0-beta.1", + "@postdfm/transform": "^6.0.0-beta.1" }, "files": [ "dist/", From 536e6f4e2fcc629bab16d4a3a9e7af365e1eade1 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 16:01:56 +1100 Subject: [PATCH 14/26] feat(@postdfm/plugin): added after hooks added after hooks for specific AST types so that plugins may hook after any children of a node have been iterated/transformed --- packages/@postdfm/plugin/src/hooks.ts | 66 ++++++++++++++++++- .../@postdfm/transform/src/transformer.ts | 9 +++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/packages/@postdfm/plugin/src/hooks.ts b/packages/@postdfm/plugin/src/hooks.ts index 4db86b56..85d42c5a 100644 --- a/packages/@postdfm/plugin/src/hooks.ts +++ b/packages/@postdfm/plugin/src/hooks.ts @@ -1,6 +1,7 @@ import * as AST from "@postdfm/ast"; import { MultiHook, SyncWaterfallHook } from "tapable"; +const AFTER_PREFIX = "after:"; export class Hooks { [AST.ASTType.String]: SyncWaterfallHook; [AST.ASTType.ControlString]: SyncWaterfallHook; @@ -22,6 +23,17 @@ export class Hooks { [AST.ASTType.Property]: SyncWaterfallHook; [AST.ASTType.Object]: SyncWaterfallHook; [AST.ASTType.Root]: SyncWaterfallHook; + after: { + [AST.ASTType.String]: SyncWaterfallHook; + [AST.ASTType.Item]: SyncWaterfallHook; + [AST.ASTType.VariantList]: SyncWaterfallHook; + [AST.ASTType.BinaryStringList]: SyncWaterfallHook; + [AST.ASTType.IdentifierList]: SyncWaterfallHook; + [AST.ASTType.ItemList]: SyncWaterfallHook; + [AST.ASTType.Property]: SyncWaterfallHook; + [AST.ASTType.Object]: SyncWaterfallHook; + [AST.ASTType.Root]: SyncWaterfallHook; + }; all: MultiHook; constructor() { @@ -119,8 +131,56 @@ export class Hooks { this[AST.ASTType.Root] = new SyncWaterfallHook(["ast"], AST.ASTType.Root); - this.all = new MultiHook( - Object.values(AST.ASTType).map((astType) => this[astType]) - ); + this.after = { + [AST.ASTType.String]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.String + ), + + [AST.ASTType.Item]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.Item + ), + + [AST.ASTType.VariantList]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.VariantList + ), + + [AST.ASTType.BinaryStringList]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.BinaryStringList + ), + + [AST.ASTType.IdentifierList]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.IdentifierList + ), + + [AST.ASTType.ItemList]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.ItemList + ), + + [AST.ASTType.Property]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.Property + ), + + [AST.ASTType.Object]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.Object + ), + + [AST.ASTType.Root]: new SyncWaterfallHook( + ["ast"], + AFTER_PREFIX + AST.ASTType.Root + ), + }; + + this.all = new MultiHook([ + ...Object.values(AST.ASTType).map((astType) => this[astType]), + ...Object.values(this.after), + ]); } } diff --git a/packages/@postdfm/transform/src/transformer.ts b/packages/@postdfm/transform/src/transformer.ts index 9960e8c7..e607516e 100644 --- a/packages/@postdfm/transform/src/transformer.ts +++ b/packages/@postdfm/transform/src/transformer.ts @@ -55,6 +55,7 @@ export class Transformer { private transformString(ast: AST.StringValue): AST.StringValue { ast = this.hooks[AST.ASTType.String].call(ast); ast.value = ast.value.map((str) => this.transform(str) as StringValuePart); + ast = this.hooks.after[AST.ASTType.String].call(ast); return ast; } @@ -109,6 +110,7 @@ export class Transformer { ast.properties = ast.properties.map((property) => this.transformProperty(property) ); + ast = this.hooks.after[AST.ASTType.Item].call(ast); return ast; } @@ -117,6 +119,7 @@ export class Transformer { ast.values = ast.values.map( (variant) => this.transform(variant) as VariantValue ); + ast = this.hooks.after[AST.ASTType.VariantList].call(ast); return ast; } @@ -127,6 +130,7 @@ export class Transformer { ast.values = ast.values.map((binaryString) => this.transformBinaryString(binaryString) ); + ast = this.hooks.after[AST.ASTType.BinaryStringList].call(ast); return ast; } @@ -135,18 +139,21 @@ export class Transformer { ast.values = ast.values.map((identifier) => this.transformIdentifier(identifier) ); + ast = this.hooks.after[AST.ASTType.IdentifierList].call(ast); return ast; } private transformItemList(ast: AST.ItemList): AST.ItemList { ast = this.hooks[AST.ASTType.ItemList].call(ast); ast.values = ast.values.map((item) => this.transformItem(item)); + ast = this.hooks.after[AST.ASTType.ItemList].call(ast); return ast; } private transformProperty(ast: AST.Property): AST.Property { ast = this.hooks[AST.ASTType.Property].call(ast); ast.value = this.transform(ast.value) as VariantValue | AnyList; + ast = this.hooks.after[AST.ASTType.Property].call(ast); return ast; } @@ -156,6 +163,7 @@ export class Transformer { this.transformProperty(property) ); ast.children = ast.children.map((child) => this.transformObject(child)); + ast = this.hooks.after[AST.ASTType.Object].call(ast); return ast; } @@ -164,6 +172,7 @@ export class Transformer { if (ast.child) { ast.child = this.transformObject(ast.child); } + ast = this.hooks.after[AST.ASTType.Root].call(ast); return ast; } } From f5205ff76bf0d22fe8d284004efacaa15472ab55 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 25 Jan 2021 05:05:59 +0000 Subject: [PATCH 15/26] chore(release): 6.0.0-beta.2 [skip ci] # [6.0.0-beta.2](https://github.com/spiltcoffee/postdfm/compare/v6.0.0-beta.1...v6.0.0-beta.2) (2021-01-25) ### Features * **@postdfm/plugin:** added after hooks ([536e6f4](https://github.com/spiltcoffee/postdfm/commit/536e6f4e2fcc629bab16d4a3a9e7af365e1eade1)) --- packages/@postdfm/ast/package.json | 2 +- packages/@postdfm/ast2dfm/package.json | 4 ++-- packages/@postdfm/dfm2ast/package.json | 4 ++-- packages/@postdfm/plugin/package.json | 4 ++-- packages/@postdfm/transform/package.json | 6 +++--- packages/postdfm/package.json | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index b0aa10aa..d5dd3f75 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Abstract Syntax Tree classes for postdfm", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index 0a2a5368..7154c11f 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast2dfm", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Convert DFM Abstract Syntax Trees to a Delphi Form file", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.1" + "@postdfm/ast": "^6.0.0-beta.2" }, "files": [ "/dist", diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index 40db523e..fb2e30b9 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/dfm2ast", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Convert Delphi Form files to an Abstract Syntax Tree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.1", + "@postdfm/ast": "^6.0.0-beta.2", "nearley": "^2.19.4" }, "files": [ diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index e4a4cf66..e7bbf770 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/plugin", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.1", + "@postdfm/ast": "^6.0.0-beta.2", "tapable": "^2.2.0" }, "files": [ diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index f6b2344c..04acdfa3 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/transform", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,8 +15,8 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.1", - "@postdfm/plugin": "^6.0.0-beta.1" + "@postdfm/ast": "^6.0.0-beta.2", + "@postdfm/plugin": "^6.0.0-beta.2" }, "files": [ "/dist", diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index b02dae53..693d33ef 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -1,6 +1,6 @@ { "name": "postdfm", - "version": "6.0.0-beta.1", + "version": "6.0.0-beta.2", "description": "Provides an API for easily transforming Delphi Forms", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast2dfm": "^6.0.0-beta.1", - "@postdfm/dfm2ast": "^6.0.0-beta.1", - "@postdfm/plugin": "^6.0.0-beta.1", - "@postdfm/transform": "^6.0.0-beta.1" + "@postdfm/ast2dfm": "^6.0.0-beta.2", + "@postdfm/dfm2ast": "^6.0.0-beta.2", + "@postdfm/plugin": "^6.0.0-beta.2", + "@postdfm/transform": "^6.0.0-beta.2" }, "files": [ "dist/", From 772c69b9fd8673b0efca472bd2090f46d802f98d Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 23:40:27 +1100 Subject: [PATCH 16/26] fix(@postdfm/plugin): changed from SyncWaterfallHook to SyncHook Giving up pretending the transformer is doing immutable operations. SyncHook will permit additional context to be provided to tappers, as well. --- packages/@postdfm/plugin/src/hooks.ts | 151 ++++++-------- .../transform/__test__/fixtures/index.test.ts | 4 +- .../@postdfm/transform/src/transformer.ts | 192 +++++++++--------- packages/postdfm/src/index.ts | 4 +- 4 files changed, 156 insertions(+), 195 deletions(-) diff --git a/packages/@postdfm/plugin/src/hooks.ts b/packages/@postdfm/plugin/src/hooks.ts index 85d42c5a..755506ce 100644 --- a/packages/@postdfm/plugin/src/hooks.ts +++ b/packages/@postdfm/plugin/src/hooks.ts @@ -1,178 +1,145 @@ import * as AST from "@postdfm/ast"; -import { MultiHook, SyncWaterfallHook } from "tapable"; +import { MultiHook, SyncHook } from "tapable"; const AFTER_PREFIX = "after:"; export class Hooks { - [AST.ASTType.String]: SyncWaterfallHook; - [AST.ASTType.ControlString]: SyncWaterfallHook; - [AST.ASTType.LiteralString]: SyncWaterfallHook; - [AST.ASTType.BinaryString]: SyncWaterfallHook; - [AST.ASTType.Integer]: SyncWaterfallHook; - [AST.ASTType.HexCode]: SyncWaterfallHook; - [AST.ASTType.Double]: SyncWaterfallHook; - [AST.ASTType.Single]: SyncWaterfallHook; - [AST.ASTType.Currency]: SyncWaterfallHook; - [AST.ASTType.DateTime]: SyncWaterfallHook; - [AST.ASTType.Boolean]: SyncWaterfallHook; - [AST.ASTType.Identifier]: SyncWaterfallHook; - [AST.ASTType.Item]: SyncWaterfallHook; - [AST.ASTType.VariantList]: SyncWaterfallHook; - [AST.ASTType.BinaryStringList]: SyncWaterfallHook; - [AST.ASTType.IdentifierList]: SyncWaterfallHook; - [AST.ASTType.ItemList]: SyncWaterfallHook; - [AST.ASTType.Property]: SyncWaterfallHook; - [AST.ASTType.Object]: SyncWaterfallHook; - [AST.ASTType.Root]: SyncWaterfallHook; + [AST.ASTType.String]: SyncHook; + [AST.ASTType.ControlString]: SyncHook; + [AST.ASTType.LiteralString]: SyncHook; + [AST.ASTType.BinaryString]: SyncHook; + [AST.ASTType.Integer]: SyncHook; + [AST.ASTType.HexCode]: SyncHook; + [AST.ASTType.Double]: SyncHook; + [AST.ASTType.Single]: SyncHook; + [AST.ASTType.Currency]: SyncHook; + [AST.ASTType.DateTime]: SyncHook; + [AST.ASTType.Boolean]: SyncHook; + [AST.ASTType.Identifier]: SyncHook; + [AST.ASTType.Item]: SyncHook; + [AST.ASTType.VariantList]: SyncHook; + [AST.ASTType.BinaryStringList]: SyncHook; + [AST.ASTType.IdentifierList]: SyncHook; + [AST.ASTType.ItemList]: SyncHook; + [AST.ASTType.Property]: SyncHook; + [AST.ASTType.Object]: SyncHook; + [AST.ASTType.Root]: SyncHook; after: { - [AST.ASTType.String]: SyncWaterfallHook; - [AST.ASTType.Item]: SyncWaterfallHook; - [AST.ASTType.VariantList]: SyncWaterfallHook; - [AST.ASTType.BinaryStringList]: SyncWaterfallHook; - [AST.ASTType.IdentifierList]: SyncWaterfallHook; - [AST.ASTType.ItemList]: SyncWaterfallHook; - [AST.ASTType.Property]: SyncWaterfallHook; - [AST.ASTType.Object]: SyncWaterfallHook; - [AST.ASTType.Root]: SyncWaterfallHook; + [AST.ASTType.String]: SyncHook; + [AST.ASTType.Item]: SyncHook; + [AST.ASTType.VariantList]: SyncHook; + [AST.ASTType.BinaryStringList]: SyncHook; + [AST.ASTType.IdentifierList]: SyncHook; + [AST.ASTType.ItemList]: SyncHook; + [AST.ASTType.Property]: SyncHook; + [AST.ASTType.Object]: SyncHook; + [AST.ASTType.Root]: SyncHook; }; all: MultiHook; constructor() { - this[AST.ASTType.String] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.String - ); + this[AST.ASTType.String] = new SyncHook(["ast"], AST.ASTType.String); - this[AST.ASTType.ControlString] = new SyncWaterfallHook( + this[AST.ASTType.ControlString] = new SyncHook( ["ast"], AST.ASTType.ControlString ); - this[AST.ASTType.LiteralString] = new SyncWaterfallHook( + this[AST.ASTType.LiteralString] = new SyncHook( ["ast"], AST.ASTType.LiteralString ); - this[AST.ASTType.BinaryString] = new SyncWaterfallHook( + this[AST.ASTType.BinaryString] = new SyncHook( ["ast"], AST.ASTType.BinaryString ); - this[AST.ASTType.Integer] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Integer - ); + this[AST.ASTType.Integer] = new SyncHook(["ast"], AST.ASTType.Integer); - this[AST.ASTType.HexCode] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.HexCode - ); + this[AST.ASTType.HexCode] = new SyncHook(["ast"], AST.ASTType.HexCode); - this[AST.ASTType.Double] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Double - ); + this[AST.ASTType.Double] = new SyncHook(["ast"], AST.ASTType.Double); - this[AST.ASTType.Single] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Single - ); + this[AST.ASTType.Single] = new SyncHook(["ast"], AST.ASTType.Single); - this[AST.ASTType.Currency] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Currency - ); + this[AST.ASTType.Currency] = new SyncHook(["ast"], AST.ASTType.Currency); - this[AST.ASTType.DateTime] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.DateTime - ); + this[AST.ASTType.DateTime] = new SyncHook(["ast"], AST.ASTType.DateTime); - this[AST.ASTType.Boolean] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Boolean - ); + this[AST.ASTType.Boolean] = new SyncHook(["ast"], AST.ASTType.Boolean); - this[AST.ASTType.Identifier] = new SyncWaterfallHook( + this[AST.ASTType.Identifier] = new SyncHook( ["ast"], AST.ASTType.Identifier ); - this[AST.ASTType.Item] = new SyncWaterfallHook(["ast"], AST.ASTType.Item); + this[AST.ASTType.Item] = new SyncHook(["ast"], AST.ASTType.Item); - this[AST.ASTType.VariantList] = new SyncWaterfallHook( + this[AST.ASTType.VariantList] = new SyncHook( ["ast"], AST.ASTType.VariantList ); - this[AST.ASTType.BinaryStringList] = new SyncWaterfallHook( + this[AST.ASTType.BinaryStringList] = new SyncHook( ["ast"], AST.ASTType.BinaryStringList ); - this[AST.ASTType.IdentifierList] = new SyncWaterfallHook( + this[AST.ASTType.IdentifierList] = new SyncHook( ["ast"], AST.ASTType.IdentifierList ); - this[AST.ASTType.ItemList] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.ItemList - ); + this[AST.ASTType.ItemList] = new SyncHook(["ast"], AST.ASTType.ItemList); - this[AST.ASTType.Property] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Property - ); + this[AST.ASTType.Property] = new SyncHook(["ast"], AST.ASTType.Property); - this[AST.ASTType.Object] = new SyncWaterfallHook( - ["ast"], - AST.ASTType.Object - ); + this[AST.ASTType.Object] = new SyncHook(["ast"], AST.ASTType.Object); - this[AST.ASTType.Root] = new SyncWaterfallHook(["ast"], AST.ASTType.Root); + this[AST.ASTType.Root] = new SyncHook(["ast"], AST.ASTType.Root); this.after = { - [AST.ASTType.String]: new SyncWaterfallHook( + [AST.ASTType.String]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.String ), - [AST.ASTType.Item]: new SyncWaterfallHook( + [AST.ASTType.Item]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.Item ), - [AST.ASTType.VariantList]: new SyncWaterfallHook( + [AST.ASTType.VariantList]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.VariantList ), - [AST.ASTType.BinaryStringList]: new SyncWaterfallHook( + [AST.ASTType.BinaryStringList]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.BinaryStringList ), - [AST.ASTType.IdentifierList]: new SyncWaterfallHook( + [AST.ASTType.IdentifierList]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.IdentifierList ), - [AST.ASTType.ItemList]: new SyncWaterfallHook( + [AST.ASTType.ItemList]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.ItemList ), - [AST.ASTType.Property]: new SyncWaterfallHook( + [AST.ASTType.Property]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.Property ), - [AST.ASTType.Object]: new SyncWaterfallHook( + [AST.ASTType.Object]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.Object ), - [AST.ASTType.Root]: new SyncWaterfallHook( + [AST.ASTType.Root]: new SyncHook( ["ast"], AFTER_PREFIX + AST.ASTType.Root ), diff --git a/packages/@postdfm/transform/__test__/fixtures/index.test.ts b/packages/@postdfm/transform/__test__/fixtures/index.test.ts index 14100078..dd13e995 100644 --- a/packages/@postdfm/transform/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/transform/__test__/fixtures/index.test.ts @@ -32,8 +32,10 @@ describe("transform", () => { const transformer = new Transformer(plugins); + transformer.transform(cisAst); + test(`${fixture}`, () => { - expect(transformer.transform(cisAst)).toEqual(transAst); + expect(cisAst).toEqual(transAst); }); }); }); diff --git a/packages/@postdfm/transform/src/transformer.ts b/packages/@postdfm/transform/src/transformer.ts index e607516e..1f9d188f 100644 --- a/packages/@postdfm/transform/src/transformer.ts +++ b/packages/@postdfm/transform/src/transformer.ts @@ -1,7 +1,4 @@ import * as AST from "@postdfm/ast"; -import { AnyList } from "@postdfm/ast/dist/list/anyList"; -import { VariantValue } from "@postdfm/ast/dist/value/variantValue"; -import { StringValuePart } from "@postdfm/ast/dist/value/stringValuePart"; import { Plugin, Hooks } from "@postdfm/plugin"; export class Transformer { @@ -13,166 +10,161 @@ export class Transformer { plugins.forEach((plugin) => plugin.install(this.hooks)); } - transform(ast: AST.ASTNode): AST.ASTNode { + transform(ast: AST.ASTNode): void { switch (ast.astType) { case AST.ASTType.String: - return this.transformString(ast as AST.StringValue); + this.transformString(ast as AST.StringValue); + break; case AST.ASTType.ControlString: - return this.transformControlString(ast as AST.ControlString); + this.transformControlString(ast as AST.ControlString); + break; case AST.ASTType.LiteralString: - return this.transformLiteralString(ast as AST.LiteralString); + this.transformLiteralString(ast as AST.LiteralString); + break; case AST.ASTType.Integer: - return this.transformInteger(ast as AST.IntegerValue); + this.transformInteger(ast as AST.IntegerValue); + break; case AST.ASTType.HexCode: - return this.transformHexCode(ast as AST.HexCodeValue); + this.transformHexCode(ast as AST.HexCodeValue); + break; case AST.ASTType.Double: - return this.transformDouble(ast as AST.DoubleValue); + this.transformDouble(ast as AST.DoubleValue); + break; case AST.ASTType.Single: - return this.transformSingle(ast as AST.SingleValue); + this.transformSingle(ast as AST.SingleValue); + break; case AST.ASTType.Currency: - return this.transformCurrency(ast as AST.CurrencyValue); + this.transformCurrency(ast as AST.CurrencyValue); + break; case AST.ASTType.DateTime: - return this.transformDateTime(ast as AST.DateTimeValue); + this.transformDateTime(ast as AST.DateTimeValue); + break; case AST.ASTType.Boolean: - return this.transformBoolean(ast as AST.BooleanValue); + this.transformBoolean(ast as AST.BooleanValue); + break; case AST.ASTType.Identifier: - return this.transformIdentifier(ast as AST.IdentifierValue); + this.transformIdentifier(ast as AST.IdentifierValue); + break; case AST.ASTType.VariantList: - return this.transformVariantList(ast as AST.VariantList); + this.transformVariantList(ast as AST.VariantList); + break; case AST.ASTType.BinaryStringList: - return this.transformBinaryStringList(ast as AST.BinaryStringList); + this.transformBinaryStringList(ast as AST.BinaryStringList); + break; case AST.ASTType.IdentifierList: - return this.transformIdentifierList(ast as AST.IdentifierList); + this.transformIdentifierList(ast as AST.IdentifierList); + break; case AST.ASTType.ItemList: - return this.transformItemList(ast as AST.ItemList); + this.transformItemList(ast as AST.ItemList); + break; case AST.ASTType.Root: - return this.transformRoot(ast as AST.Root); + this.transformRoot(ast as AST.Root); + break; default: throw Error(`Cannot generically transform astType ${ast.astType}`); } } - private transformString(ast: AST.StringValue): AST.StringValue { - ast = this.hooks[AST.ASTType.String].call(ast); - ast.value = ast.value.map((str) => this.transform(str) as StringValuePart); - ast = this.hooks.after[AST.ASTType.String].call(ast); - return ast; + private transformString(ast: AST.StringValue): void { + this.hooks[AST.ASTType.String].call(ast); + ast.value.forEach((str) => this.transform(str)); + this.hooks.after[AST.ASTType.String].call(ast); } - private transformControlString(ast: AST.ControlString): AST.ControlString { - return this.hooks[AST.ASTType.ControlString].call(ast); + private transformControlString(ast: AST.ControlString): void { + this.hooks[AST.ASTType.ControlString].call(ast); } - private transformLiteralString(ast: AST.LiteralString): AST.LiteralString { - return this.hooks[AST.ASTType.LiteralString].call(ast); + private transformLiteralString(ast: AST.LiteralString): void { + this.hooks[AST.ASTType.LiteralString].call(ast); } - private transformBinaryString( - ast: AST.BinaryStringValue - ): AST.BinaryStringValue { - return this.hooks[AST.ASTType.BinaryString].call(ast); + private transformBinaryString(ast: AST.BinaryStringValue): void { + this.hooks[AST.ASTType.BinaryString].call(ast); } - private transformInteger(ast: AST.IntegerValue): AST.IntegerValue { - return this.hooks[AST.ASTType.Integer].call(ast); + private transformInteger(ast: AST.IntegerValue): void { + this.hooks[AST.ASTType.Integer].call(ast); } - private transformHexCode(ast: AST.HexCodeValue): AST.HexCodeValue { - return this.hooks[AST.ASTType.HexCode].call(ast); + private transformHexCode(ast: AST.HexCodeValue): void { + this.hooks[AST.ASTType.HexCode].call(ast); } - private transformDouble(ast: AST.DoubleValue): AST.DoubleValue { - return this.hooks[AST.ASTType.Double].call(ast); + private transformDouble(ast: AST.DoubleValue): void { + this.hooks[AST.ASTType.Double].call(ast); } - private transformSingle(ast: AST.SingleValue): AST.SingleValue { - return this.hooks[AST.ASTType.Single].call(ast); + private transformSingle(ast: AST.SingleValue): void { + this.hooks[AST.ASTType.Single].call(ast); } - private transformCurrency(ast: AST.CurrencyValue): AST.CurrencyValue { - return this.hooks[AST.ASTType.Currency].call(ast); + private transformCurrency(ast: AST.CurrencyValue): void { + this.hooks[AST.ASTType.Currency].call(ast); } - private transformDateTime(ast: AST.DateTimeValue): AST.DateTimeValue { - return this.hooks[AST.ASTType.DateTime].call(ast); + private transformDateTime(ast: AST.DateTimeValue): void { + this.hooks[AST.ASTType.DateTime].call(ast); } - private transformBoolean(ast: AST.BooleanValue): AST.BooleanValue { - return this.hooks[AST.ASTType.Boolean].call(ast); + private transformBoolean(ast: AST.BooleanValue): void { + this.hooks[AST.ASTType.Boolean].call(ast); } - private transformIdentifier(ast: AST.IdentifierValue): AST.IdentifierValue { - return this.hooks[AST.ASTType.Identifier].call(ast); + private transformIdentifier(ast: AST.IdentifierValue): void { + this.hooks[AST.ASTType.Identifier].call(ast); } - private transformItem(ast: AST.Item): AST.Item { - ast = this.hooks[AST.ASTType.Item].call(ast); - ast.properties = ast.properties.map((property) => - this.transformProperty(property) - ); - ast = this.hooks.after[AST.ASTType.Item].call(ast); - return ast; + private transformItem(ast: AST.Item): void { + this.hooks[AST.ASTType.Item].call(ast); + ast.properties.forEach((property) => this.transformProperty(property)); + this.hooks.after[AST.ASTType.Item].call(ast); } - private transformVariantList(ast: AST.VariantList): AST.VariantList { - ast = this.hooks[AST.ASTType.VariantList].call(ast); - ast.values = ast.values.map( - (variant) => this.transform(variant) as VariantValue - ); - ast = this.hooks.after[AST.ASTType.VariantList].call(ast); - return ast; + private transformVariantList(ast: AST.VariantList): void { + this.hooks[AST.ASTType.VariantList].call(ast); + ast.values.forEach((variant) => this.transform(variant)); + this.hooks.after[AST.ASTType.VariantList].call(ast); } - private transformBinaryStringList( - ast: AST.BinaryStringList - ): AST.BinaryStringList { - ast = this.hooks[AST.ASTType.BinaryStringList].call(ast); - ast.values = ast.values.map((binaryString) => + private transformBinaryStringList(ast: AST.BinaryStringList): void { + this.hooks[AST.ASTType.BinaryStringList].call(ast); + ast.values.forEach((binaryString) => this.transformBinaryString(binaryString) ); - ast = this.hooks.after[AST.ASTType.BinaryStringList].call(ast); - return ast; + this.hooks.after[AST.ASTType.BinaryStringList].call(ast); } - private transformIdentifierList(ast: AST.IdentifierList): AST.IdentifierList { - ast = this.hooks[AST.ASTType.IdentifierList].call(ast); - ast.values = ast.values.map((identifier) => - this.transformIdentifier(identifier) - ); - ast = this.hooks.after[AST.ASTType.IdentifierList].call(ast); - return ast; + private transformIdentifierList(ast: AST.IdentifierList): void { + this.hooks[AST.ASTType.IdentifierList].call(ast); + ast.values.forEach((identifier) => this.transformIdentifier(identifier)); + this.hooks.after[AST.ASTType.IdentifierList].call(ast); } - private transformItemList(ast: AST.ItemList): AST.ItemList { - ast = this.hooks[AST.ASTType.ItemList].call(ast); - ast.values = ast.values.map((item) => this.transformItem(item)); - ast = this.hooks.after[AST.ASTType.ItemList].call(ast); - return ast; + private transformItemList(ast: AST.ItemList): void { + this.hooks[AST.ASTType.ItemList].call(ast); + ast.values.forEach((item) => this.transformItem(item)); + this.hooks.after[AST.ASTType.ItemList].call(ast); } - private transformProperty(ast: AST.Property): AST.Property { - ast = this.hooks[AST.ASTType.Property].call(ast); - ast.value = this.transform(ast.value) as VariantValue | AnyList; - ast = this.hooks.after[AST.ASTType.Property].call(ast); - return ast; + private transformProperty(ast: AST.Property): void { + this.hooks[AST.ASTType.Property].call(ast); + this.transform(ast.value); + this.hooks.after[AST.ASTType.Property].call(ast); } - private transformObject(ast: AST.DObject): AST.DObject { - ast = this.hooks[AST.ASTType.Object].call(ast); - ast.properties = ast.properties.map((property) => - this.transformProperty(property) - ); - ast.children = ast.children.map((child) => this.transformObject(child)); - ast = this.hooks.after[AST.ASTType.Object].call(ast); - return ast; + private transformObject(ast: AST.DObject): void { + this.hooks[AST.ASTType.Object].call(ast); + ast.properties.forEach((property) => this.transformProperty(property)); + ast.children.forEach((child) => this.transformObject(child)); + this.hooks.after[AST.ASTType.Object].call(ast); } - private transformRoot(ast: AST.Root): AST.Root { - ast = this.hooks[AST.ASTType.Root].call(ast); + private transformRoot(ast: AST.Root): void { + this.hooks[AST.ASTType.Root].call(ast); if (ast.child) { - ast.child = this.transformObject(ast.child); + this.transformObject(ast.child); } - ast = this.hooks.after[AST.ASTType.Root].call(ast); - return ast; + this.hooks.after[AST.ASTType.Root].call(ast); } } diff --git a/packages/postdfm/src/index.ts b/packages/postdfm/src/index.ts index 0de47e9a..efc1ffe3 100644 --- a/packages/postdfm/src/index.ts +++ b/packages/postdfm/src/index.ts @@ -68,9 +68,9 @@ export class Runner { ); } - const transformed = this.transformer.transform(ast); + this.transformer.transform(ast); - return this.options.stringifier(transformed); + return this.options.stringifier(ast); } public async process( From 5fad4d17e083f51ed1740604f9e61377a0a028a3 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Mon, 25 Jan 2021 23:59:08 +1100 Subject: [PATCH 17/26] build(release): updating release branch to main --- release.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.config.js b/release.config.js index 4aba51e6..b4582224 100644 --- a/release.config.js +++ b/release.config.js @@ -10,7 +10,7 @@ const pkgs = Object.entries( const tarballDir = path.resolve(__dirname, "dist"); module.exports = { - branch: "master", + branch: "main", repositoryUrl: "ssh://git@github.com/spiltcoffee/postdfm.git", plugins: [ "@semantic-release/commit-analyzer", From debaa006123fcc77c5288abff245a535e94b5bf0 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 00:13:36 +1100 Subject: [PATCH 18/26] build(release): updating release branch to main --- release.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.config.js b/release.config.js index b4582224..9451fc83 100644 --- a/release.config.js +++ b/release.config.js @@ -10,7 +10,7 @@ const pkgs = Object.entries( const tarballDir = path.resolve(__dirname, "dist"); module.exports = { - branch: "main", + branches: ["main", { name: "beta", prerelease: true }], repositoryUrl: "ssh://git@github.com/spiltcoffee/postdfm.git", plugins: [ "@semantic-release/commit-analyzer", From 1d3b409dc3f86bbda41fb11a27aa46283e5e0c5a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 25 Jan 2021 13:23:42 +0000 Subject: [PATCH 19/26] chore(release): 6.0.0-beta.3 [skip ci] # [6.0.0-beta.3](https://github.com/spiltcoffee/postdfm/compare/v6.0.0-beta.2...v6.0.0-beta.3) (2021-01-25) ### Bug Fixes * **@postdfm/plugin:** changed from SyncWaterfallHook to SyncHook ([772c69b](https://github.com/spiltcoffee/postdfm/commit/772c69b9fd8673b0efca472bd2090f46d802f98d)) --- packages/@postdfm/ast/package.json | 2 +- packages/@postdfm/ast2dfm/package.json | 4 ++-- packages/@postdfm/dfm2ast/package.json | 4 ++-- packages/@postdfm/plugin/package.json | 4 ++-- packages/@postdfm/transform/package.json | 6 +++--- packages/postdfm/package.json | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index d5dd3f75..3904df2b 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Abstract Syntax Tree classes for postdfm", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index 7154c11f..f42e3bfd 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast2dfm", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Convert DFM Abstract Syntax Trees to a Delphi Form file", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.2" + "@postdfm/ast": "^6.0.0-beta.3" }, "files": [ "/dist", diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index fb2e30b9..90683f7d 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/dfm2ast", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Convert Delphi Form files to an Abstract Syntax Tree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.2", + "@postdfm/ast": "^6.0.0-beta.3", "nearley": "^2.19.4" }, "files": [ diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index e7bbf770..54e31530 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/plugin", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.2", + "@postdfm/ast": "^6.0.0-beta.3", "tapable": "^2.2.0" }, "files": [ diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index 04acdfa3..1b36fdb4 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/transform", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,8 +15,8 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.2", - "@postdfm/plugin": "^6.0.0-beta.2" + "@postdfm/ast": "^6.0.0-beta.3", + "@postdfm/plugin": "^6.0.0-beta.3" }, "files": [ "/dist", diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index 693d33ef..5ebe564a 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -1,6 +1,6 @@ { "name": "postdfm", - "version": "6.0.0-beta.2", + "version": "6.0.0-beta.3", "description": "Provides an API for easily transforming Delphi Forms", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast2dfm": "^6.0.0-beta.2", - "@postdfm/dfm2ast": "^6.0.0-beta.2", - "@postdfm/plugin": "^6.0.0-beta.2", - "@postdfm/transform": "^6.0.0-beta.2" + "@postdfm/ast2dfm": "^6.0.0-beta.3", + "@postdfm/dfm2ast": "^6.0.0-beta.3", + "@postdfm/plugin": "^6.0.0-beta.3", + "@postdfm/transform": "^6.0.0-beta.3" }, "files": [ "dist/", From a7e8dba47c2752fdbb78ffc9bb795757e55ad4d4 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 11:26:11 +1100 Subject: [PATCH 20/26] docs(readme): updated readmes --- .github/CONTRIBUTING.md | 18 +++++++++--------- README.md | 25 +++++++++++-------------- packages/@postdfm/ast/README.md | 4 ++-- packages/@postdfm/ast2dfm/README.md | 4 ++-- packages/@postdfm/dfm2ast/README.md | 4 ++-- packages/@postdfm/plugin/README.md | 4 ++-- packages/@postdfm/transform/README.md | 4 ++-- packages/postdfm/README.md | 15 +++++---------- 8 files changed, 35 insertions(+), 43 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e9e567b9..83711c4c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -51,7 +51,7 @@ You will need the following software to help develop this project: Before running any commands, you'll likely have to run the following: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn install ``` @@ -60,7 +60,7 @@ $ yarn install In order to see all of the operations that would be run in the Continuous Integration, run: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn ci ``` @@ -71,7 +71,7 @@ We use `prettier` for formatting and `eslint` with `typescript-eslint` for linti To see the linting and formatting issues, run: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn lint:check $ yarn format:check ``` @@ -79,7 +79,7 @@ $ yarn format:check To have as many issues as possible fixed by the tools, run: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn lint:fix $ yarn format:fix ``` @@ -91,7 +91,7 @@ Make sure to run `format:fix` last, as that's what the CI will perform. If there `postdfm` uses TypeScript and Nearley.js, so some compilation is required. Run: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn compile ``` @@ -100,7 +100,7 @@ $ yarn compile `postdfm` uses Jest to run and report coverage of all tests in the project. Run: ```bash -~/postdfm (master) +~/postdfm (main) $ yarn test ``` @@ -109,7 +109,7 @@ $ yarn test Besides the README.md files for each project, `postdfm` uses TypeDoc to produce basic API documentation (viewable online at http://spiltcoffee.com). ```bash -~/postdfm (master) +~/postdfm (main) $ yarn docs ``` @@ -118,7 +118,7 @@ $ yarn docs The release step is performed automatically by the CI. You can run the command, but it won't do anything. ```bash -~/postdfm (master) +~/postdfm (main) $ yarn release ``` @@ -135,7 +135,7 @@ When making a commit, your code in the commit will be automatically linted, form You should try to fix whatever problems are occurring, but if you can't (like you're trying to add failing tests), please commit using the following: ```bash -~/postdfm (master) +~/postdfm (main) $ git commit --no-verify ``` diff --git a/README.md b/README.md index b6f1b517..cae41707 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ > > Inspired by the excellent PostCSS tool, motivated by my rage at the Delphi IDE. -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=package.json) ## Table of Contents @@ -18,12 +18,14 @@ ## Packages -| Package | Version | -| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | -| [`postdfm`](/packages/postdfm) | [![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) | -| [`@postdfm/ast`](/packages/@postdfm/ast) | [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) | -| [`@postdfm/ast2dfm`](/packages/@postdfm/ast2dfm) | [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) | -| [`@postdfm/dfm2ast`](/packages/@postdfm/dfm2ast) | [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) | +| Package | Version | +| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| [`postdfm`](/packages/postdfm) | [![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) | +| [`@postdfm/ast`](/packages/@postdfm/ast) | [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) | +| [`@postdfm/ast2dfm`](/packages/@postdfm/ast2dfm) | [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) | +| [`@postdfm/dfm2ast`](/packages/@postdfm/dfm2ast) | [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) | +| [`@postdfm/plugin`](/packages/@postdfm/plugin) | [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) | +| [`@postdfm/transform`](/packages/@postdfm/transform) | [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) | ## Installation @@ -50,12 +52,7 @@ const cisDfm = fs.readFileSync( ); const runner = postdfm({ - transformers: [ - function (ast) { - //transform and return the ast - return transformedAst; - }, - ], + transformers: [new Plugin()], }); const transDfm = runner.processSync(dfm, { diff --git a/packages/@postdfm/ast/README.md b/packages/@postdfm/ast/README.md index e6943463..5c039681 100644 --- a/packages/@postdfm/ast/README.md +++ b/packages/@postdfm/ast/README.md @@ -1,8 +1,8 @@ # @postdfm/ast [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast/package.json) Sub-package for `postdfm`. diff --git a/packages/@postdfm/ast2dfm/README.md b/packages/@postdfm/ast2dfm/README.md index 3ab712eb..81ee1ff9 100644 --- a/packages/@postdfm/ast2dfm/README.md +++ b/packages/@postdfm/ast2dfm/README.md @@ -1,8 +1,8 @@ # @postdfm/ast2dfm [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast2dfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast2dfm/package.json) Sub-package for `postdfm`. diff --git a/packages/@postdfm/dfm2ast/README.md b/packages/@postdfm/dfm2ast/README.md index fd84e860..4317c4c8 100644 --- a/packages/@postdfm/dfm2ast/README.md +++ b/packages/@postdfm/dfm2ast/README.md @@ -1,8 +1,8 @@ # @postdfm/dfm2ast [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/dfm2ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/dfm2ast/package.json) Sub-package for `postdfm`. diff --git a/packages/@postdfm/plugin/README.md b/packages/@postdfm/plugin/README.md index 78e16222..94756fe7 100644 --- a/packages/@postdfm/plugin/README.md +++ b/packages/@postdfm/plugin/README.md @@ -1,8 +1,8 @@ # @postdfm/plugin [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/plugin/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/plugin/package.json) Sub-package for `postdfm`. diff --git a/packages/@postdfm/transform/README.md b/packages/@postdfm/transform/README.md index c20f01a7..f0aa193e 100644 --- a/packages/@postdfm/transform/README.md +++ b/packages/@postdfm/transform/README.md @@ -1,8 +1,8 @@ # @postdfm/transform [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/transform/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/transform/package.json) Sub-package for `postdfm`. diff --git a/packages/postdfm/README.md b/packages/postdfm/README.md index 965ff640..e33934cf 100644 --- a/packages/postdfm/README.md +++ b/packages/postdfm/README.md @@ -5,8 +5,8 @@ > Inspired by the excellent PostCSS tool, motivated by my rage at the Delphi IDE. [![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) -[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/master.svg)](https://circleci.com) -[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/master.svg)](https://codecov.io) +[![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) +[![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/postdfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/postdfm/package.json) ## Table of Contents @@ -42,12 +42,7 @@ const cisDfm = fs.readFileSync( ); const runner = postdfm({ - transformers: [ - function (ast) { - //transform and return the ast - return transformedAst; - }, - ], + transformers: [new Plugin()], }); const transDfm = runner.processSync(dfm, { @@ -85,7 +80,7 @@ Process a file through the runner synchronously. Options to pass to an instance of `Runner`. -#### `options.transformers: Transformer[]` +#### `options.plugins: Plugin[]` Array of transformations to perform on AST. @@ -135,7 +130,7 @@ You can find the generated `typedoc` documentation [here](https://spiltcoffee.co Bug reports and feature requests are greatly appreciated, as are pull requests. -Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/master/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. ## License From 80633d0584a92f5774b2fb5feb5631c503b4813b Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 17:34:24 +1100 Subject: [PATCH 21/26] fix(@postdfm/dfm2ast): fixed parser to interpret nameless object correctly Nameless objects were incorrectly being interpreted as having a name and no type, rather than a type and no name BREAKING CHANGE: Nameless objects will now define the type and leave the name undefined fix #180 --- .../parse/boundary-keyword/ast.json | 6 +-- .../__fixtures__/parse/empty-object/ast.json | 2 +- .../__fixtures__/parse/everything/ast.json | 32 +++++++++----- .../__fixtures__/parse/everything/form.dfm | 2 + __test__/__fixtures__/parse/lists/ast.json | 2 +- __test__/__fixtures__/parse/no-type/ast.json | 4 +- __test__/__fixtures__/parse/no-type/form.dfm | 2 +- __test__/__fixtures__/parse/objects/ast.json | 42 ++++++++++++------- __test__/__fixtures__/parse/objects/form.dfm | 2 + .../__fixtures__/parse/properties/ast.json | 2 +- __test__/__fixtures__/parse/strings/ast.json | 2 +- .../__fixtures__/parse/weird-spacing/ast.json | 20 ++++----- .../transform/everything/cis.json | 20 ++++----- .../transform/everything/trans.json | 20 ++++----- .../transform/hello-world/cis.json | 2 +- .../transform/hello-world/trans.json | 2 +- packages/@postdfm/ast/src/object.ts | 2 +- .../ast2dfm/__test__/fixtures/index.test.ts | 2 +- packages/@postdfm/ast2dfm/src/stringifier.ts | 9 ++-- .../dfm2ast/__test__/fixtures/index.test.ts | 2 +- packages/@postdfm/dfm2ast/ne/object.ne | 24 +++++------ 21 files changed, 115 insertions(+), 86 deletions(-) diff --git a/__test__/__fixtures__/parse/boundary-keyword/ast.json b/__test__/__fixtures__/parse/boundary-keyword/ast.json index 0671a904..2efce8c0 100644 --- a/__test__/__fixtures__/parse/boundary-keyword/ast.json +++ b/__test__/__fixtures__/parse/boundary-keyword/ast.json @@ -37,7 +37,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeEnd": "\r\n " } } @@ -45,7 +45,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n " @@ -55,7 +55,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n" } diff --git a/__test__/__fixtures__/parse/empty-object/ast.json b/__test__/__fixtures__/parse/empty-object/ast.json index bde6ead2..cca96dd2 100644 --- a/__test__/__fixtures__/parse/empty-object/ast.json +++ b/__test__/__fixtures__/parse/empty-object/ast.json @@ -9,7 +9,7 @@ "raws": { "afterName": "", "beforeEnd": "\r\n", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TEmpty" diff --git a/__test__/__fixtures__/parse/everything/ast.json b/__test__/__fixtures__/parse/everything/ast.json index 5d4b34ef..2d49566f 100644 --- a/__test__/__fixtures__/parse/everything/ast.json +++ b/__test__/__fixtures__/parse/everything/ast.json @@ -122,7 +122,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -222,7 +222,7 @@ "afterType": " ", "beforeOrder": "", "afterOrder": "", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -453,7 +453,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -574,7 +574,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -651,7 +651,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -719,7 +719,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -773,7 +773,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -782,7 +782,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -798,7 +798,19 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", + "beforeEnd": "\r\n ", + "before": "\r\n " + } + }, + { + "astType": "object", + "kind": "object", + "type": "TNameless", + "properties": [], + "children": [], + "raws": { + "beforeDef": " ", "beforeEnd": "\r\n ", "before": "\r\n " } @@ -807,7 +819,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n" diff --git a/__test__/__fixtures__/parse/everything/form.dfm b/__test__/__fixtures__/parse/everything/form.dfm index fa053e51..f8b63541 100644 --- a/__test__/__fixtures__/parse/everything/form.dfm +++ b/__test__/__fixtures__/parse/everything/form.dfm @@ -66,4 +66,6 @@ object Form1: TForm1 end object Nothing: _TNothing end + object TNameless + end end diff --git a/__test__/__fixtures__/parse/lists/ast.json b/__test__/__fixtures__/parse/lists/ast.json index b7584246..47d6cb71 100644 --- a/__test__/__fixtures__/parse/lists/ast.json +++ b/__test__/__fixtures__/parse/lists/ast.json @@ -415,7 +415,7 @@ "raws": { "afterName": "", "beforeEnd": "\r\n", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeType": " " }, diff --git a/__test__/__fixtures__/parse/no-type/ast.json b/__test__/__fixtures__/parse/no-type/ast.json index f3557fec..f4413df0 100644 --- a/__test__/__fixtures__/parse/no-type/ast.json +++ b/__test__/__fixtures__/parse/no-type/ast.json @@ -4,11 +4,11 @@ "astType": "object", "children": [], "kind": "object", - "name": "Empty", + "type": "TEmpty", "properties": [], "raws": { "beforeEnd": "\r\n", - "beforeName": " " + "beforeDef": " " } }, "raws": { diff --git a/__test__/__fixtures__/parse/no-type/form.dfm b/__test__/__fixtures__/parse/no-type/form.dfm index bf12854c..fb58f855 100644 --- a/__test__/__fixtures__/parse/no-type/form.dfm +++ b/__test__/__fixtures__/parse/no-type/form.dfm @@ -1,2 +1,2 @@ -object Empty +object TEmpty end \ No newline at end of file diff --git a/__test__/__fixtures__/parse/objects/ast.json b/__test__/__fixtures__/parse/objects/ast.json index 854d1d94..6c5a0cb6 100644 --- a/__test__/__fixtures__/parse/objects/ast.json +++ b/__test__/__fixtures__/parse/objects/ast.json @@ -12,7 +12,7 @@ "raws": { "afterName": "", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TEdit" @@ -27,7 +27,7 @@ "afterName": "", "before": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TEdit" @@ -42,11 +42,23 @@ "afterName": "", "before": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TEdit" }, + { + "astType": "object", + "children": [], + "kind": "object", + "type": "TNameless", + "properties": [], + "raws": { + "before": "\r\n ", + "beforeEnd": "\r\n ", + "beforeDef": " " + } + }, { "astType": "object", "children": [ @@ -86,7 +98,7 @@ "raws": { "afterName": "", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -99,7 +111,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -112,7 +124,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -125,7 +137,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -138,7 +150,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -151,7 +163,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -164,7 +176,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -177,7 +189,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -190,7 +202,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -203,7 +215,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "TComponent" @@ -217,7 +229,7 @@ "before": "\r\n ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", - "beforeName": " ", + "beforeDef": " ", "beforeType": " " }, "type": "_TUnder_Score" @@ -248,7 +260,7 @@ "afterName": "", "beforeChildren": "\r\n ", "beforeEnd": "\r\n", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeType": " " }, diff --git a/__test__/__fixtures__/parse/objects/form.dfm b/__test__/__fixtures__/parse/objects/form.dfm index 3aa0f5ab..e5339a2d 100644 --- a/__test__/__fixtures__/parse/objects/form.dfm +++ b/__test__/__fixtures__/parse/objects/form.dfm @@ -6,6 +6,8 @@ object BasicForm: TForm end inherited Edit3: TEdit end + object TNameless + end object _Under_Score: _TUnder_Score object DeepTree1: TComponent object DeepTree2: TComponent diff --git a/__test__/__fixtures__/parse/properties/ast.json b/__test__/__fixtures__/parse/properties/ast.json index ab686091..576035cd 100644 --- a/__test__/__fixtures__/parse/properties/ast.json +++ b/__test__/__fixtures__/parse/properties/ast.json @@ -306,8 +306,8 @@ ], "raws": { "afterName": "", + "beforeDef": " ", "beforeEnd": "\r\n", - "beforeName": " ", "beforeProperties": "\r\n ", "beforeType": " " }, diff --git a/__test__/__fixtures__/parse/strings/ast.json b/__test__/__fixtures__/parse/strings/ast.json index 5b2b2022..c5a13958 100644 --- a/__test__/__fixtures__/parse/strings/ast.json +++ b/__test__/__fixtures__/parse/strings/ast.json @@ -150,8 +150,8 @@ ], "raws": { "afterName": "", + "beforeDef": " ", "beforeEnd": "\r\n", - "beforeName": " ", "beforeProperties": "\r\n ", "beforeType": " " }, diff --git a/__test__/__fixtures__/parse/weird-spacing/ast.json b/__test__/__fixtures__/parse/weird-spacing/ast.json index a7a37e3c..45953980 100644 --- a/__test__/__fixtures__/parse/weird-spacing/ast.json +++ b/__test__/__fixtures__/parse/weird-spacing/ast.json @@ -56,8 +56,8 @@ ], "raws": { "afterName": "", + "beforeDef": " ", "beforeEnd": "\r\n ", - "beforeName": " ", "beforeProperties": "\r\n ", "beforeType": " " }, @@ -156,8 +156,8 @@ "afterOrder": "", "afterType": " ", "before": "\r\n\r\n ", + "beforeDef": " ", "beforeEnd": "\r\n ", - "beforeName": " ", "beforeOrder": "", "beforeProperties": "\r\n\r\n ", "beforeType": " " @@ -388,8 +388,8 @@ "raws": { "afterName": "", "before": "\r\n ", + "beforeDef": " ", "beforeEnd": "\r\n ", - "beforeName": " ", "beforeProperties": "\r\n ", "beforeType": " " }, @@ -509,8 +509,8 @@ "raws": { "afterName": "", "before": "\r\n ", + "beforeDef": " ", "beforeEnd": "\r\n ", - "beforeName": " ", "beforeProperties": "\r\n ", "beforeType": " " }, @@ -588,8 +588,8 @@ "raws": { "afterName": "", "before": "\r\n ", + "beforeDef": " ", "beforeEnd": " ", - "beforeName": " ", "beforeProperties": " ", "beforeType": " " }, @@ -656,8 +656,8 @@ "raws": { "afterName": "", "before": "\r\n ", + "beforeDef": " ", "beforeEnd": "\r\n ", - "beforeName": " ", "beforeProperties": "\r\n\r\n\r\n ", "beforeType": " " }, @@ -705,8 +705,8 @@ ], "raws": { "afterName": "", + "beforeDef": " ", "beforeEnd": "\r\n", - "beforeName": " ", "beforeProperties": "\r\n", "beforeType": " " }, @@ -720,8 +720,8 @@ "afterName": "", "before": "\r\n", "beforeChildren": "\r\n", + "beforeDef": " ", "beforeEnd": "\r\n", - "beforeName": " ", "beforeType": " " }, "type": "TForm2" @@ -735,8 +735,8 @@ "raws": { "afterName": "", "before": "\r\n", + "beforeDef": " ", "beforeEnd": "\r\n", - "beforeName": " ", "beforeType": " " }, "type": "_TNothing" @@ -808,8 +808,8 @@ "raws": { "afterName": "", "beforeChildren": " ", + "beforeDef": "\r\n\r\n\r\n\r\n ", "beforeEnd": "\r\n", - "beforeName": "\r\n\r\n\r\n\r\n ", "beforeProperties": "\r\n ", "beforeType": " " }, diff --git a/__test__/__fixtures__/transform/everything/cis.json b/__test__/__fixtures__/transform/everything/cis.json index 5d4b34ef..7829d691 100644 --- a/__test__/__fixtures__/transform/everything/cis.json +++ b/__test__/__fixtures__/transform/everything/cis.json @@ -122,7 +122,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -222,7 +222,7 @@ "afterType": " ", "beforeOrder": "", "afterOrder": "", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -453,7 +453,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -574,7 +574,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -651,7 +651,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -719,7 +719,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -773,7 +773,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -782,7 +782,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -798,7 +798,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeEnd": "\r\n ", "before": "\r\n " } @@ -807,7 +807,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n" diff --git a/__test__/__fixtures__/transform/everything/trans.json b/__test__/__fixtures__/transform/everything/trans.json index 22e9b947..aa8aa7e1 100644 --- a/__test__/__fixtures__/transform/everything/trans.json +++ b/__test__/__fixtures__/transform/everything/trans.json @@ -122,7 +122,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -222,7 +222,7 @@ "afterType": " ", "beforeOrder": "", "afterOrder": "", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -453,7 +453,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -574,7 +574,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -651,7 +651,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -719,7 +719,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -773,7 +773,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n " } @@ -782,7 +782,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n ", "before": "\r\n " @@ -798,7 +798,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeEnd": "\r\n ", "before": "\r\n " } @@ -807,7 +807,7 @@ "raws": { "afterName": "", "beforeType": " ", - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeChildren": "\r\n ", "beforeEnd": "\r\n" diff --git a/__test__/__fixtures__/transform/hello-world/cis.json b/__test__/__fixtures__/transform/hello-world/cis.json index 01d4c3ef..f29c2308 100644 --- a/__test__/__fixtures__/transform/hello-world/cis.json +++ b/__test__/__fixtures__/transform/hello-world/cis.json @@ -25,7 +25,7 @@ ], "children": [], "raws": { - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n" } diff --git a/__test__/__fixtures__/transform/hello-world/trans.json b/__test__/__fixtures__/transform/hello-world/trans.json index 4a7f067f..783ee986 100644 --- a/__test__/__fixtures__/transform/hello-world/trans.json +++ b/__test__/__fixtures__/transform/hello-world/trans.json @@ -25,7 +25,7 @@ ], "children": [], "raws": { - "beforeName": " ", + "beforeDef": " ", "beforeProperties": "\r\n ", "beforeEnd": "\r\n" } diff --git a/packages/@postdfm/ast/src/object.ts b/packages/@postdfm/ast/src/object.ts index 2662ad13..f3a9707d 100644 --- a/packages/@postdfm/ast/src/object.ts +++ b/packages/@postdfm/ast/src/object.ts @@ -5,7 +5,7 @@ import { ObjectKind } from "./objectKind"; import { Property } from "./property"; interface ObjectRaws extends ASTRaws { - beforeName?: string; + beforeDef?: string; afterName?: string; beforeType?: string; afterType?: string; diff --git a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts index b7b338a9..5cf0681c 100644 --- a/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/ast2dfm/__test__/fixtures/index.test.ts @@ -7,7 +7,7 @@ const rootFixturesDir = path.join("__test__", "__fixtures__"); const parseFixturesDir = path.join(rootFixturesDir, "parse"); describe("dfm2ast", () => { - describe("fixtures", () => { + describe("parse fixtures", () => { const fixtures = fs.readdirSync(parseFixturesDir); fixtures.forEach((fixture) => { const astFile = path.join(parseFixturesDir, fixture, "ast.json"); diff --git a/packages/@postdfm/ast2dfm/src/stringifier.ts b/packages/@postdfm/ast2dfm/src/stringifier.ts index 55d9bc01..e5bfd751 100644 --- a/packages/@postdfm/ast2dfm/src/stringifier.ts +++ b/packages/@postdfm/ast2dfm/src/stringifier.ts @@ -229,12 +229,13 @@ export default class Stringifier { return this.print( raws.before, ast.kind, - raws.beforeName, + raws.beforeDef, ast.name, raws.afterName, - ast.type - ? this.print(":", raws.beforeType, ast.type, raws.afterType) - : "", + ast.name ? ":" : "", + raws.beforeType, + ast.type, + raws.afterType, ast.order !== undefined ? this.print( "[", diff --git a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts index 70e2de0b..9b6ebc9c 100644 --- a/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts +++ b/packages/@postdfm/dfm2ast/__test__/fixtures/index.test.ts @@ -6,7 +6,7 @@ const rootFixturesDir = path.join("__test__", "__fixtures__"); const parseFixturesDir = path.join(rootFixturesDir, "parse"); describe("dfm2ast", () => { - describe("fixtures", () => { + describe("parse fixtures", () => { const fixtures = fs.readdirSync(parseFixturesDir); fixtures.forEach((fixture) => { const formFile = path.join(parseFixturesDir, fixture, "form.dfm"); diff --git a/packages/@postdfm/dfm2ast/ne/object.ne b/packages/@postdfm/dfm2ast/ne/object.ne index afd8bdae..b8b64840 100644 --- a/packages/@postdfm/dfm2ast/ne/object.ne +++ b/packages/@postdfm/dfm2ast/ne/object.ne @@ -1,28 +1,28 @@ object -> objectKind _ objectDef __ "end"i -{% ([kind, beforeName, { name, type, order, raws: defRaws }, beforeEnd]) => { +{% ([kind, beforeDef, { name, type, order, raws: defRaws }, beforeEnd]) => { const node = new AST.DObject(kind, name, type, order); - node.raws = { ...(defRaws || {}), beforeName, beforeEnd }; + node.raws = { ...(defRaws || {}), beforeDef, beforeEnd }; return node; } %} object -> objectKind _ objectDef _ properties __ "end"i -{% ([kind, beforeName, { name, type, order, raws: defRaws }, beforeProperties, properties, beforeEnd]) => { +{% ([kind, beforeDef, { name, type, order, raws: defRaws }, beforeProperties, properties, beforeEnd]) => { const node = new AST.DObject(kind, name, type, order, properties) - node.raws = { ...(defRaws || {}), beforeName, beforeProperties, beforeEnd }; + node.raws = { ...(defRaws || {}), beforeDef, beforeProperties, beforeEnd }; return node; } %} object -> objectKind _ objectDef _ objects __ "end"i -{% ([kind, beforeName, { name, type, order, raws: defRaws }, beforeChildren, children, beforeEnd]) => { +{% ([kind, beforeDef, { name, type, order, raws: defRaws }, beforeChildren, children, beforeEnd]) => { const node = new AST.DObject(kind, name, type, order, undefined, children); - node.raws = { ...(defRaws || {}), beforeName, beforeChildren, beforeEnd }; + node.raws = { ...(defRaws || {}), beforeDef, beforeChildren, beforeEnd }; return node; } %} object -> objectKind _ objectDef _ properties _ objects __ "end"i -{% ([kind, beforeName, { name, type, order, raws: defRaws }, beforeProperties, properties, beforeChildren, children, beforeEnd]) => { +{% ([kind, beforeDef, { name, type, order, raws: defRaws }, beforeProperties, properties, beforeChildren, children, beforeEnd]) => { const node = new AST.DObject(kind, name, type, order, properties, children); - node.raws = { ...(defRaws || {}), beforeName, beforeProperties, beforeChildren, beforeEnd }; + node.raws = { ...(defRaws || {}), beforeDef, beforeProperties, beforeChildren, beforeEnd }; return node; } %} @@ -34,7 +34,7 @@ objectKind -> "object"i {% () => AST.ObjectKind.Object %} objectDef -> identifer -{% ([name]) => ({ name }) %} +{% ([type]) => ({ type }) %} objectDef -> identifer _ ":" _ identifer {% ([name, afterName, _, beforeType, type]) => ({ @@ -48,11 +48,11 @@ objectDef -> identifer _ ":" _ identifer #is this one valid? objectDef -> identifer _ "[" _ decimal _ "]" -{% ([name, afterName, _, beforeOrder, order, afterOrder]) => ({ - name, +{% ([type, afterType, _, beforeOrder, order, afterOrder]) => ({ + type, order, raws: { - afterName, + afterType, beforeOrder, afterOrder } From 4aad500eaae3b4da4d56ce80652510a97510508c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 26 Jan 2021 06:42:42 +0000 Subject: [PATCH 22/26] chore(release): 6.0.0-beta.4 [skip ci] # [6.0.0-beta.4](https://github.com/spiltcoffee/postdfm/compare/v6.0.0-beta.3...v6.0.0-beta.4) (2021-01-26) ### Bug Fixes * **@postdfm/dfm2ast:** fixed parser to interpret nameless object correctly ([80633d0](https://github.com/spiltcoffee/postdfm/commit/80633d0584a92f5774b2fb5feb5631c503b4813b)), closes [#180](https://github.com/spiltcoffee/postdfm/issues/180) ### BREAKING CHANGES * **@postdfm/dfm2ast:** Nameless objects will now define the type and leave the name undefined --- packages/@postdfm/ast/package.json | 2 +- packages/@postdfm/ast2dfm/package.json | 4 ++-- packages/@postdfm/dfm2ast/package.json | 4 ++-- packages/@postdfm/plugin/package.json | 4 ++-- packages/@postdfm/transform/package.json | 6 +++--- packages/postdfm/package.json | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index 3904df2b..f634f1ed 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Abstract Syntax Tree classes for postdfm", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index f42e3bfd..c001a83f 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast2dfm", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Convert DFM Abstract Syntax Trees to a Delphi Form file", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.3" + "@postdfm/ast": "^6.0.0-beta.4" }, "files": [ "/dist", diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index 90683f7d..6afb992f 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/dfm2ast", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Convert Delphi Form files to an Abstract Syntax Tree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.3", + "@postdfm/ast": "^6.0.0-beta.4", "nearley": "^2.19.4" }, "files": [ diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index 54e31530..068a8849 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/plugin", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.3", + "@postdfm/ast": "^6.0.0-beta.4", "tapable": "^2.2.0" }, "files": [ diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index 1b36fdb4..80f2fc03 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/transform", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,8 +15,8 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.3", - "@postdfm/plugin": "^6.0.0-beta.3" + "@postdfm/ast": "^6.0.0-beta.4", + "@postdfm/plugin": "^6.0.0-beta.4" }, "files": [ "/dist", diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index 5ebe564a..761a8c5a 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -1,6 +1,6 @@ { "name": "postdfm", - "version": "6.0.0-beta.3", + "version": "6.0.0-beta.4", "description": "Provides an API for easily transforming Delphi Forms", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast2dfm": "^6.0.0-beta.3", - "@postdfm/dfm2ast": "^6.0.0-beta.3", - "@postdfm/plugin": "^6.0.0-beta.3", - "@postdfm/transform": "^6.0.0-beta.3" + "@postdfm/ast2dfm": "^6.0.0-beta.4", + "@postdfm/dfm2ast": "^6.0.0-beta.4", + "@postdfm/plugin": "^6.0.0-beta.4", + "@postdfm/transform": "^6.0.0-beta.4" }, "files": [ "dist/", From 8cc5dcd95536f5450b31f3fa2043a23e355146ed Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 17:50:34 +1100 Subject: [PATCH 23/26] fix(@postdfm/dfm2ast): concat to existing array rather than constructing new one Concat to existing array rather than constructing new one fix #104 --- packages/@postdfm/dfm2ast/ne/list.ne | 8 ++++---- packages/@postdfm/dfm2ast/ne/object.ne | 2 +- packages/@postdfm/dfm2ast/ne/primitive.ne | 4 ++-- packages/@postdfm/dfm2ast/ne/property.ne | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/@postdfm/dfm2ast/ne/list.ne b/packages/@postdfm/dfm2ast/ne/list.ne index 78b94979..e57ec6f2 100644 --- a/packages/@postdfm/dfm2ast/ne/list.ne +++ b/packages/@postdfm/dfm2ast/ne/list.ne @@ -6,7 +6,7 @@ commaValues -> commaValues _ "," _ value const prevValue = values[values.length - 1]; prevValue.raws = { ...(prevValue.raws || {}), after }; value.raws = { ...(value.raws || {}), before }; - return [].concat(values, value); + return values.concat(value); }%} variantValues -> value @@ -15,7 +15,7 @@ variantValues -> value variantValues -> variantValues __ value {% ([values, before, value]) => { value.raws = { ...(values.raws || {}), before }; - return [].concat(values, value); + return values.concat(value); } %} binaryValues -> binaryString @@ -24,7 +24,7 @@ binaryValues -> binaryString binaryValues -> binaryValues __ binaryString {% ([values, before, value]) => { value.raws = { ...(value.raws || {}), before }; - return [].concat(values, value); + return values.concat(value); }%} itemValues -> item @@ -33,7 +33,7 @@ itemValues -> item itemValues -> itemValues _ item {% ([items, before, item]) => { item.raws = { ...(item.raws || {}), before }; - return [].concat(items, item); + return items.concat(item); } %} identifierList -> "[" _ "]" diff --git a/packages/@postdfm/dfm2ast/ne/object.ne b/packages/@postdfm/dfm2ast/ne/object.ne index b8b64840..4374d17a 100644 --- a/packages/@postdfm/dfm2ast/ne/object.ne +++ b/packages/@postdfm/dfm2ast/ne/object.ne @@ -81,5 +81,5 @@ objects -> objects __ object ...(object.raws || {}), before }; - return [].concat(objects, object); + return objects.concat(object); } %} diff --git a/packages/@postdfm/dfm2ast/ne/primitive.ne b/packages/@postdfm/dfm2ast/ne/primitive.ne index 448e2d58..3b299deb 100644 --- a/packages/@postdfm/dfm2ast/ne/primitive.ne +++ b/packages/@postdfm/dfm2ast/ne/primitive.ne @@ -30,7 +30,7 @@ string -> string singleString prevValue.value += "'" + value.value; return values; } else { - return [].concat(values, value) + return values.concat(value) } } %} @@ -40,7 +40,7 @@ stringSep -> _ "+" _ string -> string stringSep singleString {% ([values, before, value]) => { value.raws = { ...(value.raws || {}), before }; - return [].concat(values, value); + return values.concat(value); } %} singleString -> controlChar diff --git a/packages/@postdfm/dfm2ast/ne/property.ne b/packages/@postdfm/dfm2ast/ne/property.ne index c74340f1..4e615879 100644 --- a/packages/@postdfm/dfm2ast/ne/property.ne +++ b/packages/@postdfm/dfm2ast/ne/property.ne @@ -1,10 +1,10 @@ properties -> property -{% properties => properties %} +{% ([property]) => [property] %} properties -> properties _ property {% ([properties, before, property]) => { property.raws = { ...(property.raws || {}), before }; - return [].concat(properties, property); + return properties.concat(property); } %} property -> qualifiedIdentifier _ "=" _ value From 1a58cc9fe6994fbd0bccecbc225033d44a743c3c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 26 Jan 2021 06:59:14 +0000 Subject: [PATCH 24/26] chore(release): 6.0.0-beta.5 [skip ci] # [6.0.0-beta.5](https://github.com/spiltcoffee/postdfm/compare/v6.0.0-beta.4...v6.0.0-beta.5) (2021-01-26) ### Bug Fixes * **@postdfm/dfm2ast:** concat to existing array rather than constructing new one ([8cc5dcd](https://github.com/spiltcoffee/postdfm/commit/8cc5dcd95536f5450b31f3fa2043a23e355146ed)), closes [#104](https://github.com/spiltcoffee/postdfm/issues/104) --- packages/@postdfm/ast/package.json | 2 +- packages/@postdfm/ast2dfm/package.json | 4 ++-- packages/@postdfm/dfm2ast/package.json | 4 ++-- packages/@postdfm/plugin/package.json | 4 ++-- packages/@postdfm/transform/package.json | 6 +++--- packages/postdfm/package.json | 10 +++++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index f634f1ed..b4d4c6eb 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Abstract Syntax Tree classes for postdfm", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index c001a83f..072baa92 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/ast2dfm", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Convert DFM Abstract Syntax Trees to a Delphi Form file", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.4" + "@postdfm/ast": "^6.0.0-beta.5" }, "files": [ "/dist", diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index 6afb992f..b381892c 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/dfm2ast", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Convert Delphi Form files to an Abstract Syntax Tree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -16,7 +16,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.4", + "@postdfm/ast": "^6.0.0-beta.5", "nearley": "^2.19.4" }, "files": [ diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index 068a8849..75820d7e 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/plugin", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Provides structure and utilities for making plugins that can modify a postdfm AST.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,7 +15,7 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.4", + "@postdfm/ast": "^6.0.0-beta.5", "tapable": "^2.2.0" }, "files": [ diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index 80f2fc03..a72ea49b 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -1,6 +1,6 @@ { "name": "@postdfm/transform", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Iterates a Delphi Form Abstract Syntax Tree, allowing modification via Hooks", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -15,8 +15,8 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast": "^6.0.0-beta.4", - "@postdfm/plugin": "^6.0.0-beta.4" + "@postdfm/ast": "^6.0.0-beta.5", + "@postdfm/plugin": "^6.0.0-beta.5" }, "files": [ "/dist", diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index 761a8c5a..9a14afe7 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -1,6 +1,6 @@ { "name": "postdfm", - "version": "6.0.0-beta.4", + "version": "6.0.0-beta.5", "description": "Provides an API for easily transforming Delphi Forms", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/spiltcoffee/postdfm#readme", "dependencies": { - "@postdfm/ast2dfm": "^6.0.0-beta.4", - "@postdfm/dfm2ast": "^6.0.0-beta.4", - "@postdfm/plugin": "^6.0.0-beta.4", - "@postdfm/transform": "^6.0.0-beta.4" + "@postdfm/ast2dfm": "^6.0.0-beta.5", + "@postdfm/dfm2ast": "^6.0.0-beta.5", + "@postdfm/plugin": "^6.0.0-beta.5", + "@postdfm/transform": "^6.0.0-beta.5" }, "files": [ "dist/", From 01bc791b9b66b1ea98c9572103cc41675996e781 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 18:52:02 +1100 Subject: [PATCH 25/26] docs(readme): updated readmes --- packages/@postdfm/ast/README.md | 22 +++++++++- packages/@postdfm/ast2dfm/README.md | 22 +++++++++- packages/@postdfm/dfm2ast/README.md | 22 +++++++++- packages/@postdfm/plugin/README.md | 60 ++++++++++++++++++++++++++- packages/@postdfm/transform/README.md | 22 +++++++++- packages/postdfm/README.md | 36 ++++++++++++---- 6 files changed, 167 insertions(+), 17 deletions(-) diff --git a/packages/@postdfm/ast/README.md b/packages/@postdfm/ast/README.md index 5c039681..aa970283 100644 --- a/packages/@postdfm/ast/README.md +++ b/packages/@postdfm/ast/README.md @@ -1,12 +1,30 @@ # @postdfm/ast +> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> +> Provides the AST structures used by `postdfm`. + [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) [![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast/package.json) -Sub-package for `postdfm`. +## Table of Contents + +- [Documentation](#documentation) +- [Contributing](#contributing) +- [License](#license) -Provides the AST structures used by `postdfm`. +## Documentation See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/@postdfm/ast2dfm/README.md b/packages/@postdfm/ast2dfm/README.md index 81ee1ff9..2df6819c 100644 --- a/packages/@postdfm/ast2dfm/README.md +++ b/packages/@postdfm/ast2dfm/README.md @@ -1,12 +1,30 @@ # @postdfm/ast2dfm +> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> +> Provides functionality for turning the structure provided by `@postdfm/ast` into a string. + [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) [![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/ast2dfm/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/ast2dfm/package.json) -Sub-package for `postdfm`. +## Table of Contents + +- [Documentation](#documentation) +- [Contributing](#contributing) +- [License](#license) -Provides functionality for turning the structure provided by `@postdfm/ast` into a string. +## Documentation See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast2dfm/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/@postdfm/dfm2ast/README.md b/packages/@postdfm/dfm2ast/README.md index 4317c4c8..667d6779 100644 --- a/packages/@postdfm/dfm2ast/README.md +++ b/packages/@postdfm/dfm2ast/README.md @@ -1,12 +1,30 @@ # @postdfm/dfm2ast +> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> +> Provides functionality for parsing DFMs into the structures provided by `@postdfm/ast`. + [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) [![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/dfm2ast/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/dfm2ast/package.json) -Sub-package for `postdfm`. +## Table of Contents + +- [Documentation](#documentation) +- [Contributing](#contributing) +- [License](#license) -Provides functionality for parsing DFMs into the structures provided by `@postdfm/ast`. +## Documentation See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/dfm2ast/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/@postdfm/plugin/README.md b/packages/@postdfm/plugin/README.md index 94756fe7..9430bcc6 100644 --- a/packages/@postdfm/plugin/README.md +++ b/packages/@postdfm/plugin/README.md @@ -1,12 +1,68 @@ # @postdfm/plugin +> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> +> Provides structure and utilities for making plugins that can modify a `@postdfm/ast` Abstract Syntax Tree. + [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) [![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/plugin/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/plugin/package.json) -Sub-package for `postdfm`. +## Table of Contents + +- [Installation](#installation) +- [Example Usage](#example-usage) +- [Documentation](#documentation) +- [Contributing](#contributing) +- [License](#license) + +## Installation + +```shell +# npm +$ npm install @postdfm/plugin + +# yarn +$ yarn add @postdfm/plugin +``` + +## Example Usage + +```js +const { Plugin } = require("@postdfm/plugin"); + +class SomePlugin extends Plugin { + install(hooks) { + hooks.string.tap(ast => { + // manipulate AST here + } -Provides structure and utilities for making plugins that can modify a `@postdfm/ast` Abstract Syntax Tree. + // all AST types can be manipulated, see AST.ASTTypes + + // also available: + // - "after" hook for certain types + hooks.after.object.tap(ast => { + // manipulate AST here + }) + // - "all" hook for everything - excludes "after" hooks + hooks.all.tap(ast => { + // manipulate AST here + }) + } +} +``` + +## Documentation See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/plugin/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/@postdfm/transform/README.md b/packages/@postdfm/transform/README.md index f0aa193e..0d06c612 100644 --- a/packages/@postdfm/transform/README.md +++ b/packages/@postdfm/transform/README.md @@ -1,12 +1,30 @@ # @postdfm/transform +> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> +> Provides functionality for iterating a `@postdfm/ast` Abstract Syntax Tree via Hooks (using Webpack's Tapable package). + [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) [![Codecov branch](https://img.shields.io/codecov/c/gh/spiltcoffee/postdfm/main.svg)](https://codecov.io) [![Known Vulnerabilities](https://snyk.io/test/github/spiltcoffee/postdfm/badge.svg?targetFile=packages/@postdfm/transform/package.json)](https://snyk.io/test/github/spiltcoffee/postdfm?targetFile=packages/@postdfm/transform/package.json) -Sub-package for `postdfm`. +## Table of Contents + +- [Documentation](#documentation) +- [Contributing](#contributing) +- [License](#license) -Provides functionality for iterating a `@postdfm/ast` Abstract Syntax Tree via Hooks (using Webpack's Tapable package). +## Documentation See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/transform/). + +## Contributing + +Bug reports and feature requests are greatly appreciated, as are pull requests. + +Please see the [Contributing Guide](https://github.com/spiltcoffee/postdfm/blob/main/.github/CONTRIBUTING.md) for instructions on how to contribute to this project. + +## License + +Licensed under the MIT License. diff --git a/packages/postdfm/README.md b/packages/postdfm/README.md index e33934cf..c95dab83 100644 --- a/packages/postdfm/README.md +++ b/packages/postdfm/README.md @@ -14,6 +14,7 @@ - [Installation](#installation) - [Example Usage](#example-usage) - [Reference](#reference) +- [Documentation](#documentation) - [Contributing](#contributing) - [License](#license) @@ -35,6 +36,29 @@ $ yarn add postdfm const fs = require("fs"); const postdfm = require("postdfm"); +// if implementing your own plugin, otherwise import plugins +const { Plugin } = require("@postdfm/plugin"); + +class SomePlugin extends Plugin { + install(hooks) { + hooks.string.tap(ast => { + // manipulate AST here + } + + // all AST types can be manipulated, see AST.ASTTypes + + // also available: + // - "after" hook for certain types + hooks.after.object.tap(ast => { + // manipulate AST here + }) + // - "all" hook for everything - excludes "after" hooks + hooks.all.tap(ast => { + // manipulate AST here + }) + } +} + const cisDfm = fs.readFileSync( "cis.dfm", //.dfm files tend to be ascii instead of utf8 @@ -42,7 +66,7 @@ const cisDfm = fs.readFileSync( ); const runner = postdfm({ - transformers: [new Plugin()], + transformers: [new SomePlugin()], }); const transDfm = runner.processSync(dfm, { @@ -92,13 +116,11 @@ Parser to use, defaults to `@postdfm/dfm2ast`. Stringifier to use, defaults to `@postdfm/ast2dfm`. -### `Transformer` +### `Plugin` -A function that takes an AST, transforms it, and returns it. +A class that extends the `@postdfm/plugin` Plugin, extending the `install()` method. -```js -(ast: AST.Root): AST.Root -``` +See [`@postdfm/plugin`](https://github.com/spiltcoffee/postdfm/blob/main/packages/%40postdfm/plugin/README.md) for more information. ### `Parser` @@ -122,7 +144,7 @@ A function that takes an AST, stringifies it, and returns a string. The file which is being processed. Used when throwing syntax errors. -## Generated Documentation +## Documentation You can find the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/postdfm/). From e2ce8a4527a46e7fc3be08a4b4184bf0358c5a52 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Tue, 26 Jan 2021 20:08:18 +1100 Subject: [PATCH 26/26] docs(readme): update readmes --- README.md | 57 ++++++--------------------- packages/@postdfm/ast/README.md | 6 +-- packages/@postdfm/ast2dfm/README.md | 6 +-- packages/@postdfm/dfm2ast/README.md | 6 +-- packages/@postdfm/plugin/README.md | 6 +-- packages/@postdfm/transform/README.md | 6 +-- 6 files changed, 27 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index cae41707..90f3de82 100644 --- a/README.md +++ b/README.md @@ -11,59 +11,26 @@ ## Table of Contents - [Packages](#packages) -- [Installation](#installation) -- [Example Usage](#example-usage) +- [Usage](#usage) - [Contributing](#contributing) - [License](#license) ## Packages -| Package | Version | -| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | -| [`postdfm`](/packages/postdfm) | [![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) | -| [`@postdfm/ast`](/packages/@postdfm/ast) | [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) | -| [`@postdfm/ast2dfm`](/packages/@postdfm/ast2dfm) | [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) | -| [`@postdfm/dfm2ast`](/packages/@postdfm/dfm2ast) | [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) | -| [`@postdfm/plugin`](/packages/@postdfm/plugin) | [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) | -| [`@postdfm/transform`](/packages/@postdfm/transform) | [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) | +| Package | Version | +| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| [`postdfm` (README)](/packages/postdfm) | [![npm](https://img.shields.io/npm/v/postdfm.svg?label=npm)](https://www.npmjs.com/package/postdfm) | +| [`@postdfm/ast` (README)](/packages/@postdfm/ast) | [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) | +| [`@postdfm/ast2dfm` (README)](/packages/@postdfm/ast2dfm) | [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) | +| [`@postdfm/dfm2ast` (README)](/packages/@postdfm/dfm2ast) | [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) | +| [`@postdfm/plugin` (README)](/packages/@postdfm/plugin) | [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) | +| [`@postdfm/transform` (README)](/packages/@postdfm/transform) | [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) | -## Installation +## Usage -The `postdfm` project is an interface wrapping all the separate modules together. +See the [`postdfm`](/packages/postdfm) package for usage information. -```shell -# npm -$ npm install postdfm - -# yarn -$ yarn add postdfm -``` - -## Example Usage - -```js -const fs = require("fs"); -const postdfm = require("postdfm"); - -const cisDfm = fs.readFileSync( - "cis.dfm", - //.dfm files tend to be ascii instead of utf8 - "ascii" -); - -const runner = postdfm({ - transformers: [new Plugin()], -}); - -const transDfm = runner.processSync(dfm, { - //filename used for reporting errors - from: "cis.dfm", -}); - -fs.writeFileSync("trans.dfm", transDfm); -``` - -See the [`postdfm`](packages/postdfm) package for more information. +See the [`@postdfm/plugin`](/packages/@postdfm/plugin) package for Plugin usage information. ## Contributing diff --git a/packages/@postdfm/ast/README.md b/packages/@postdfm/ast/README.md index aa970283..05e5d437 100644 --- a/packages/@postdfm/ast/README.md +++ b/packages/@postdfm/ast/README.md @@ -1,8 +1,8 @@ # @postdfm/ast -> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> Sub-package for [`postdfm`](https://www.npmjs.com/package/postdfm). > -> Provides the AST structures used by `postdfm`. +> Provides Abstract Syntax Tree structures for representing the contents of a Delphi Form File. [![npm](https://img.shields.io/npm/v/@postdfm/ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) @@ -17,7 +17,7 @@ ## Documentation -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast/). +See [`postdfm`](https://www.npmjs.com/package/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast/). ## Contributing diff --git a/packages/@postdfm/ast2dfm/README.md b/packages/@postdfm/ast2dfm/README.md index 2df6819c..c9aaf2ae 100644 --- a/packages/@postdfm/ast2dfm/README.md +++ b/packages/@postdfm/ast2dfm/README.md @@ -1,8 +1,8 @@ # @postdfm/ast2dfm -> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> Sub-package for [`postdfm`](https://www.npmjs.com/package/postdfm). > -> Provides functionality for turning the structure provided by `@postdfm/ast` into a string. +> Provides functionality for turning the structure provided by [`@postdfm/ast`](https://www.npmjs.com/package/@postdfm/ast) into a string/DFM. [![npm](https://img.shields.io/npm/v/@postdfm/ast2dfm.svg?label=npm)](https://www.npmjs.com/package/@postdfm/ast2dfm) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) @@ -17,7 +17,7 @@ ## Documentation -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast2dfm/). +See [`postdfm`](https://www.npmjs.com/package/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/ast2dfm/). ## Contributing diff --git a/packages/@postdfm/dfm2ast/README.md b/packages/@postdfm/dfm2ast/README.md index 667d6779..d4ebf457 100644 --- a/packages/@postdfm/dfm2ast/README.md +++ b/packages/@postdfm/dfm2ast/README.md @@ -1,8 +1,8 @@ # @postdfm/dfm2ast -> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> Sub-package for [`postdfm`](https://www.npmjs.com/package/postdfm). > -> Provides functionality for parsing DFMs into the structures provided by `@postdfm/ast`. +> Provides functionality for parsing DFMs into the structures provided by [`@postdfm/ast`](https://www.npmjs.com/package/@postdfm/ast). [![npm](https://img.shields.io/npm/v/@postdfm/dfm2ast.svg?label=npm)](https://www.npmjs.com/package/@postdfm/dfm2ast) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) @@ -17,7 +17,7 @@ ## Documentation -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/dfm2ast/). +See [`postdfm`](https://www.npmjs.com/package/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/dfm2ast/). ## Contributing diff --git a/packages/@postdfm/plugin/README.md b/packages/@postdfm/plugin/README.md index 9430bcc6..c9f28228 100644 --- a/packages/@postdfm/plugin/README.md +++ b/packages/@postdfm/plugin/README.md @@ -1,8 +1,8 @@ # @postdfm/plugin -> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> Sub-package for [`postdfm`](https://www.npmjs.com/package/postdfm). > -> Provides structure and utilities for making plugins that can modify a `@postdfm/ast` Abstract Syntax Tree. +> Provides structure and utilities for making plugins that can modify the structure provided by [`@postdfm/ast`](https://www.npmjs.com/package/@postdfm/ast). [![npm](https://img.shields.io/npm/v/@postdfm/plugin.svg?label=npm)](https://www.npmjs.com/package/@postdfm/plugin) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) @@ -55,7 +55,7 @@ class SomePlugin extends Plugin { ## Documentation -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/plugin/). +See [`postdfm`](https://www.npmjs.com/package/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/plugin/). ## Contributing diff --git a/packages/@postdfm/transform/README.md b/packages/@postdfm/transform/README.md index 0d06c612..d774e055 100644 --- a/packages/@postdfm/transform/README.md +++ b/packages/@postdfm/transform/README.md @@ -1,8 +1,8 @@ # @postdfm/transform -> Sub-package for [`postdfm`](https://github.com/spiltcoffee/postdfm). +> Sub-package for [`postdfm`](https://www.npmjs.com/package/postdfm). > -> Provides functionality for iterating a `@postdfm/ast` Abstract Syntax Tree via Hooks (using Webpack's Tapable package). +> Provides functionality for iterating the structure provided by [`@postdfm/ast`](https://www.npmjs.com/package/@postdfm/ast) via ([Webpack Tapable](https://www.npmjs.com/package/tapable)) Hooks. [![npm](https://img.shields.io/npm/v/@postdfm/transform.svg?label=npm)](https://www.npmjs.com/package/@postdfm/transform) [![CircleCI branch](https://img.shields.io/circleci/project/github/spiltcoffee/postdfm/main.svg)](https://circleci.com) @@ -17,7 +17,7 @@ ## Documentation -See [`postdfm`](https://github.com/spiltcoffee/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/transform/). +See [`postdfm`](https://www.npmjs.com/package/postdfm) for more information, or the generated `typedoc` documentation [here](https://spiltcoffee.com/docs/@postdfm/transform/). ## Contributing