From 0b74be78304f8206f1b36627206fb517924e08e4 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Mon, 16 Mar 2020 22:37:36 +1000 Subject: [PATCH 1/5] feat(core): allow to pass dynamic data in options for render (#59) --- packages/bbob-core/src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/bbob-core/src/index.js b/packages/bbob-core/src/index.js index e2bd5bd5..cb01d20e 100644 --- a/packages/bbob-core/src/index.js +++ b/packages/bbob-core/src/index.js @@ -18,6 +18,7 @@ export default function bbob(plugs) { const parseFn = options.parser || parse; const renderFn = options.render; + const data = options.data || null; if (typeof parseFn !== 'function') { throw new Error('"parser" is not a function, please pass to "process(input, { parser })" right function'); @@ -41,6 +42,7 @@ export default function bbob(plugs) { render: renderFn, iterate, match, + data, }) || tree; }); From 0a213abbf7f5790f7ae7df9848fd523cc796df13 Mon Sep 17 00:00:00 2001 From: Nikolay Kostyurin Date: Thu, 26 Mar 2020 00:23:01 +0200 Subject: [PATCH 2/5] chore(lerna): add options for commit message and publishing --- lerna.json | 7 ++++++- package.json | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lerna.json b/lerna.json index b45e4441..fbc57f79 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,6 @@ { "lerna": "2.11.0", + "version": "2.5.4", "packages": [ "packages/bbob-cli", "packages/bbob-core", @@ -15,5 +16,9 @@ "access": "public", "registry": "https://registry.npmjs.org/" }, - "version": "2.5.4" + "command": { + "version": { + "message": "chore(release): publish %s" + } + } } diff --git a/package.json b/package.json index ea855b0b..e663fa4d 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "scripts": { "prepublishOnly": "npm run test", "bootstrap": "lerna bootstrap", - "publish-all": "lerna run --parallel build && lerna publish --conventional-commits --registry=https://registry.npmjs.org/", - "publish-patch": "lerna run --parallel build && lerna publish --conventional-commits --cd-version patch --registry=https://registry.npmjs.org/", + "publish-all": "lerna run --parallel build && lerna publish --include-merged-tags --conventional-commits --create-release github --registry=https://registry.npmjs.org/", + "publish-patch": "lerna run --parallel build && lerna publish --include-merged-tags --conventional-commits --create-release github --cd-version patch --registry=https://registry.npmjs.org/", "size": "lerna run --parallel size", "bundlesize": "lerna run --parallel bundlesize", "test": "npm run build && lerna run --parallel link && lerna run --parallel test", From 2670fc128892a48c636c5669b61af06f9824f057 Mon Sep 17 00:00:00 2001 From: Nikolay Kostyurin Date: Thu, 26 Mar 2020 00:51:02 +0200 Subject: [PATCH 3/5] chore(release): publish v2.5.5 --- CHANGELOG.md | 11 +++++++++++ lerna.json | 2 +- packages/bbob-cli/CHANGELOG.md | 8 ++++++++ packages/bbob-cli/package-lock.json | 2 +- packages/bbob-cli/package.json | 6 +++--- packages/bbob-core/CHANGELOG.md | 11 +++++++++++ packages/bbob-core/package-lock.json | 2 +- packages/bbob-core/package.json | 4 ++-- packages/bbob-html/CHANGELOG.md | 8 ++++++++ packages/bbob-html/package-lock.json | 2 +- packages/bbob-html/package.json | 6 +++--- packages/bbob-parser/CHANGELOG.md | 8 ++++++++ packages/bbob-parser/package-lock.json | 2 +- packages/bbob-parser/package.json | 4 ++-- packages/bbob-plugin-helper/CHANGELOG.md | 8 ++++++++ packages/bbob-plugin-helper/package-lock.json | 2 +- packages/bbob-plugin-helper/package.json | 2 +- packages/bbob-preset-html5/CHANGELOG.md | 8 ++++++++ packages/bbob-preset-html5/package-lock.json | 2 +- packages/bbob-preset-html5/package.json | 8 ++++---- packages/bbob-preset-react/CHANGELOG.md | 8 ++++++++ packages/bbob-preset-react/package-lock.json | 2 +- packages/bbob-preset-react/package.json | 6 +++--- packages/bbob-preset/CHANGELOG.md | 8 ++++++++ packages/bbob-preset/package-lock.json | 2 +- packages/bbob-preset/package.json | 4 ++-- packages/bbob-react/CHANGELOG.md | 8 ++++++++ packages/bbob-react/package-lock.json | 2 +- packages/bbob-react/package.json | 10 +++++----- 29 files changed, 121 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f63dd234..0eb37a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + + +### Features + +* **core:** allow to pass dynamic data in options for render ([#59](https://github.com/JiLiZART/bbob/issues/59)) ([0b74be7](https://github.com/JiLiZART/bbob/commit/0b74be78304f8206f1b36627206fb517924e08e4)) + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/lerna.json b/lerna.json index fbc57f79..c48ca414 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "lerna": "2.11.0", - "version": "2.5.4", + "version": "2.5.5", "packages": [ "packages/bbob-cli", "packages/bbob-core", diff --git a/packages/bbob-cli/CHANGELOG.md b/packages/bbob-cli/CHANGELOG.md index e6bb5ead..7ba25d14 100644 --- a/packages/bbob-cli/CHANGELOG.md +++ b/packages/bbob-cli/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/cli + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-cli/package-lock.json b/packages/bbob-cli/package-lock.json index 9d3c6742..754273c5 100644 --- a/packages/bbob-cli/package-lock.json +++ b/packages/bbob-cli/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/cli", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-cli/package.json b/packages/bbob-cli/package.json index 87f70da9..f3d74e69 100644 --- a/packages/bbob-cli/package.json +++ b/packages/bbob-cli/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/cli", - "version": "2.5.4", + "version": "2.5.5", "description": "Comand line bbcode parser", "main": "lib/cli.js", "bin": { @@ -10,8 +10,8 @@ "lib": "lib" }, "dependencies": { - "@bbob/html": "^2.5.4", - "@bbob/preset-html5": "^2.5.4", + "@bbob/html": "^2.5.5", + "@bbob/preset-html5": "^2.5.5", "commander": "^2.15.1" }, "repository": { diff --git a/packages/bbob-core/CHANGELOG.md b/packages/bbob-core/CHANGELOG.md index ea790b25..da3686d3 100644 --- a/packages/bbob-core/CHANGELOG.md +++ b/packages/bbob-core/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + + +### Features + +* **core:** allow to pass dynamic data in options for render ([#59](https://github.com/JiLiZART/bbob/issues/59)) ([0b74be7](https://github.com/JiLiZART/bbob/commit/0b74be78304f8206f1b36627206fb517924e08e4)) + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-core/package-lock.json b/packages/bbob-core/package-lock.json index 9892fb03..19a85f92 100644 --- a/packages/bbob-core/package-lock.json +++ b/packages/bbob-core/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/core", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-core/package.json b/packages/bbob-core/package.json index e85dcb90..c63eb7ca 100644 --- a/packages/bbob-core/package.json +++ b/packages/bbob-core/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/core", - "version": "2.5.4", + "version": "2.5.5", "description": "⚡️Blazing fast BBCode transforming and parsing tool in pure javascript, no dependencies ", "keywords": [ "bbcode", @@ -20,7 +20,7 @@ "core" ], "dependencies": { - "@bbob/parser": "^2.5.4" + "@bbob/parser": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-html/CHANGELOG.md b/packages/bbob-html/CHANGELOG.md index 61f47cd1..9b04cc03 100644 --- a/packages/bbob-html/CHANGELOG.md +++ b/packages/bbob-html/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/html + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-html/package-lock.json b/packages/bbob-html/package-lock.json index e436409c..46ee7cd2 100644 --- a/packages/bbob-html/package-lock.json +++ b/packages/bbob-html/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/html", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-html/package.json b/packages/bbob-html/package.json index 18898769..e1676d42 100644 --- a/packages/bbob-html/package.json +++ b/packages/bbob-html/package.json @@ -1,11 +1,11 @@ { "name": "@bbob/html", - "version": "2.5.4", + "version": "2.5.5", "description": "HTML renderer for @bbob bbcode parser", "keywords": [], "dependencies": { - "@bbob/core": "^2.5.4", - "@bbob/plugin-helper": "^2.5.4" + "@bbob/core": "^2.5.5", + "@bbob/plugin-helper": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-parser/CHANGELOG.md b/packages/bbob-parser/CHANGELOG.md index f4e0fe2e..bdb15387 100644 --- a/packages/bbob-parser/CHANGELOG.md +++ b/packages/bbob-parser/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/parser + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-parser/package-lock.json b/packages/bbob-parser/package-lock.json index cb473068..d4a8c746 100644 --- a/packages/bbob-parser/package-lock.json +++ b/packages/bbob-parser/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/parser", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-parser/package.json b/packages/bbob-parser/package.json index 55b5144a..4bb0e3d6 100644 --- a/packages/bbob-parser/package.json +++ b/packages/bbob-parser/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/parser", - "version": "2.5.4", + "version": "2.5.5", "description": "Just parses BBcode to AST array. Part of @bbob bbcode parser", "keywords": [ "bbcode", @@ -13,7 +13,7 @@ "parse" ], "dependencies": { - "@bbob/plugin-helper": "^2.5.4" + "@bbob/plugin-helper": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-plugin-helper/CHANGELOG.md b/packages/bbob-plugin-helper/CHANGELOG.md index ee70ac52..21cac89d 100644 --- a/packages/bbob-plugin-helper/CHANGELOG.md +++ b/packages/bbob-plugin-helper/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/plugin-helper + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-plugin-helper/package-lock.json b/packages/bbob-plugin-helper/package-lock.json index a948dc9e..88f8182d 100644 --- a/packages/bbob-plugin-helper/package-lock.json +++ b/packages/bbob-plugin-helper/package-lock.json @@ -1,5 +1,5 @@ { "name": "@bbob/plugin-helper", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1 } diff --git a/packages/bbob-plugin-helper/package.json b/packages/bbob-plugin-helper/package.json index b0b696ff..81bf074d 100644 --- a/packages/bbob-plugin-helper/package.json +++ b/packages/bbob-plugin-helper/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/plugin-helper", - "version": "2.5.4", + "version": "2.5.5", "description": "Set of utils to help write plugins for @bbob/core", "keywords": [ "bbob", diff --git a/packages/bbob-preset-html5/CHANGELOG.md b/packages/bbob-preset-html5/CHANGELOG.md index 7f2c2963..f61eef0f 100644 --- a/packages/bbob-preset-html5/CHANGELOG.md +++ b/packages/bbob-preset-html5/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/preset-html5 + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-preset-html5/package-lock.json b/packages/bbob-preset-html5/package-lock.json index 94fd57be..7da83d28 100644 --- a/packages/bbob-preset-html5/package-lock.json +++ b/packages/bbob-preset-html5/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset-html5", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-preset-html5/package.json b/packages/bbob-preset-html5/package.json index 8cacb1c3..c4c9c682 100644 --- a/packages/bbob-preset-html5/package.json +++ b/packages/bbob-preset-html5/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset-html5", - "version": "2.5.4", + "version": "2.5.5", "description": "HTML5 preset to transform BBCode to HTML for @bbob/parser", "keywords": [ "preset", @@ -8,11 +8,11 @@ "bbob" ], "dependencies": { - "@bbob/plugin-helper": "^2.5.4", - "@bbob/preset": "^2.5.4" + "@bbob/plugin-helper": "^2.5.5", + "@bbob/preset": "^2.5.5" }, "devDependencies": { - "@bbob/html": "^2.5.4" + "@bbob/html": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-preset-react/CHANGELOG.md b/packages/bbob-preset-react/CHANGELOG.md index ae84164f..efebb344 100644 --- a/packages/bbob-preset-react/CHANGELOG.md +++ b/packages/bbob-preset-react/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/preset-react + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-preset-react/package-lock.json b/packages/bbob-preset-react/package-lock.json index 457788b0..6db24818 100644 --- a/packages/bbob-preset-react/package-lock.json +++ b/packages/bbob-preset-react/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset-react", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-preset-react/package.json b/packages/bbob-preset-react/package.json index a86ef65f..f25cf6f4 100644 --- a/packages/bbob-preset-react/package.json +++ b/packages/bbob-preset-react/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset-react", - "version": "2.5.4", + "version": "2.5.5", "description": "React preset to transform BBCode to React for @bbob/react", "keywords": [ "bbob", @@ -8,10 +8,10 @@ "react" ], "dependencies": { - "@bbob/preset-html5": "^2.5.4" + "@bbob/preset-html5": "^2.5.5" }, "devDependencies": { - "@bbob/core": "^2.5.4" + "@bbob/core": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-preset/CHANGELOG.md b/packages/bbob-preset/CHANGELOG.md index 4bbc4582..1342d2e3 100644 --- a/packages/bbob-preset/CHANGELOG.md +++ b/packages/bbob-preset/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/preset + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-preset/package-lock.json b/packages/bbob-preset/package-lock.json index 532451e4..9eda97ea 100644 --- a/packages/bbob-preset/package-lock.json +++ b/packages/bbob-preset/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-preset/package.json b/packages/bbob-preset/package.json index 1698af92..3d77f0fa 100644 --- a/packages/bbob-preset/package.json +++ b/packages/bbob-preset/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/preset", - "version": "2.5.4", + "version": "2.5.5", "description": "Base preset for creating extensible presets for @bbob/core", "keywords": [ "preset", @@ -8,7 +8,7 @@ "bbob" ], "dependencies": { - "@bbob/plugin-helper": "^2.5.4" + "@bbob/plugin-helper": "^2.5.5" }, "main": "lib/index.js", "module": "es/index.js", diff --git a/packages/bbob-react/CHANGELOG.md b/packages/bbob-react/CHANGELOG.md index da13710b..b0a055da 100644 --- a/packages/bbob-react/CHANGELOG.md +++ b/packages/bbob-react/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25) + +**Note:** Version bump only for package @bbob/react + + + + + ## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25) diff --git a/packages/bbob-react/package-lock.json b/packages/bbob-react/package-lock.json index a3fcb4b8..85196ea4 100644 --- a/packages/bbob-react/package-lock.json +++ b/packages/bbob-react/package-lock.json @@ -1,6 +1,6 @@ { "name": "@bbob/react", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/packages/bbob-react/package.json b/packages/bbob-react/package.json index 8acdf7d0..e8b228f4 100644 --- a/packages/bbob-react/package.json +++ b/packages/bbob-react/package.json @@ -1,6 +1,6 @@ { "name": "@bbob/react", - "version": "2.5.4", + "version": "2.5.5", "description": "Render BBCode to React using @bbob/parser", "keywords": [ "react", @@ -9,16 +9,16 @@ "bbob" ], "dependencies": { - "@bbob/core": "^2.5.4", - "@bbob/html": "^2.5.4", - "@bbob/plugin-helper": "^2.5.4" + "@bbob/core": "^2.5.5", + "@bbob/html": "^2.5.5", + "@bbob/plugin-helper": "^2.5.5" }, "peerDependencies": { "prop-types": "15.x", "react": "15.x" }, "devDependencies": { - "@bbob/preset-react": "^2.5.4", + "@bbob/preset-react": "^2.5.5", "enzyme": "^3.9.0", "enzyme-adapter-react-15": "^1.0.6", "react": "15.x", From e3727dc5f5bcda42d42aab0439e4ddcfbae298af Mon Sep 17 00:00:00 2001 From: Nikolay Kostyurin Date: Thu, 26 Mar 2020 01:00:52 +0200 Subject: [PATCH 4/5] chore(readme): update codesandbox examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd9de9a6..4c9eb3f0 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,7 @@ const App = ({ renderProp }) => ( render() // Super easy to render ``` -[![Edit x7w52lqmzz](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/x7w52lqmzz) +[![Edit x7w52lqmzz](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jovial-cohen-bvo08) ### PostHTML usage From 97ecba0af61c05ab4f57516589e64c7419138fde Mon Sep 17 00:00:00 2001 From: Nikolay Kostyurin Date: Sun, 5 Apr 2020 15:08:59 +0200 Subject: [PATCH 5/5] perf(parser): optimize v8 perf deoptimizations (#61) --- packages/bbob-parser/src/Token.js | 69 +++++++++++++++++++++++++++---- packages/bbob-parser/src/parse.js | 12 +++++- packages/bbob-parser/src/utils.js | 26 ++++++++++-- 3 files changed, 93 insertions(+), 14 deletions(-) diff --git a/packages/bbob-parser/src/Token.js b/packages/bbob-parser/src/Token.js index 8ae9ddf8..6c5159cb 100644 --- a/packages/bbob-parser/src/Token.js +++ b/packages/bbob-parser/src/Token.js @@ -17,19 +17,70 @@ const TOKEN_TYPE_ATTR_VALUE = 'attr-value'; const TOKEN_TYPE_SPACE = 'space'; const TOKEN_TYPE_NEW_LINE = 'new-line'; -const getTokenValue = (token) => token[TOKEN_VALUE_ID]; -const getTokenLine = (token) => token[TOKEN_LINE_ID]; -const getTokenColumn = (token) => token[TOKEN_COLUMN_ID]; +/** + * @param {Token} token + * @returns {string} + */ +const getTokenValue = (token) => { + if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') { + return token[TOKEN_VALUE_ID]; + } + + return ''; +}; +/** + * @param {Token}token + * @returns {number} + */ +const getTokenLine = (token) => (token && token[TOKEN_LINE_ID]) || 0; +const getTokenColumn = (token) => (token && token[TOKEN_COLUMN_ID]) || 0; + +/** + * @param {Token} token + * @returns {boolean} + */ +const isTextToken = (token) => { + if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { + return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE + || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE + || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD; + } -const isTextToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE - || token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE - || token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD; + return false; +}; + +/** + * @param {Token} token + * @returns {boolean} + */ +const isTagToken = (token) => { + if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { + return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; + } -const isTagToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG; + return false; +}; const isTagEnd = (token) => getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0); const isTagStart = (token) => !isTagEnd(token); -const isAttrNameToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; -const isAttrValueToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; +const isAttrNameToken = (token) => { + if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { + return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME; + } + + return false; +}; + +/** + * @param {Token} token + * @returns {boolean} + */ +const isAttrValueToken = (token) => { + if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') { + return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE; + } + + return false; +}; const getTagName = (token) => { const value = getTokenValue(token); diff --git a/packages/bbob-parser/src/parse.js b/packages/bbob-parser/src/parse.js index 93d92838..2bb697f0 100644 --- a/packages/bbob-parser/src/parse.js +++ b/packages/bbob-parser/src/parse.js @@ -77,7 +77,11 @@ const parse = (input, opts = {}) => { const getNodes = () => { const lastNestedNode = nestedNodes.getLast(); - return lastNestedNode ? lastNestedNode.content : nodes.toArray(); + if (lastNestedNode && Array.isArray(lastNestedNode.content)) { + return lastNestedNode.content; + } + + return nodes.toArray(); }; /** @@ -85,7 +89,11 @@ const parse = (input, opts = {}) => { * @param {TagNode} tag */ const appendNodes = (tag) => { - getNodes().push(tag); + const items = getNodes(); + + if (Array.isArray(items)) { + items.push(tag); + } }; /** diff --git a/packages/bbob-parser/src/utils.js b/packages/bbob-parser/src/utils.js index 7d00d0b6..b6d11df2 100644 --- a/packages/bbob-parser/src/utils.js +++ b/packages/bbob-parser/src/utils.js @@ -57,8 +57,22 @@ export const createCharGrabber = (source, options) => { return source.substr(start, cursor.pos - start); }, - getNext: () => source[cursor.pos + 1], - getPrev: () => source[cursor.pos - 1], + getNext: () => { + const nextPos = cursor.pos + 1; + + if (nextPos <= (source.length - 1)) { + return source[nextPos]; + } + return null; + }, + getPrev: () => { + const prevPos = cursor.pos - 1; + + if (typeof source[prevPos] !== 'undefined') { + return source[prevPos]; + } + return null; + }, getCurr, getRest, /** @@ -127,7 +141,13 @@ export const createList = (values = []) => { /** * @callback getLastCb */ - const getLast = () => (nodes.length ? nodes[nodes.length - 1] : null); + const getLast = () => { + if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') { + return nodes[nodes.length - 1]; + } + + return null; + }; /** * @callback flushLastCb * @return {*}