Commit ef39ee9b authored by Roy Revelt's avatar Roy Revelt

feat: rewrite

rewrite

BREAKING CHANGE: rewrite
parent de384b5a
......@@ -3,6 +3,19 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## 2.0.0 (2020-05-12)
### Complete rewrite. But no changes to API. Still bumping major.
We switched to all in-house components:
- `codsen-parser` ([npm](https://www.npmjs.com/package/codsen-parser)/[monorepo](https://gitlab.com/codsen/codsen/tree/master/packages/codsen-parser/)) — produces AST
- `ast-monkey-traverse-with-lookahead` ([npm](https://www.npmjs.com/package/ast-monkey-traverse-with-lookahead)/[monorepo](https://gitlab.com/codsen/codsen/tree/master/packages/ast-monkey-traverse-with-lookahead/)) — traverses that AST
- `ranges-push` ([npm](https://www.npmjs.com/package/ranges-push)/[monorepo](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-push/)) — records what needs to be done in source code while traversing AST
- `ranges-apply` ([npm](https://www.npmjs.com/package/ranges-apply)/[monorepo](https://gitlab.com/codsen/codsen/tree/master/packages/ranges-apply/)) — performs all amends in string in one go when finished traversing AST
As a result, UMD bundle is half-the size (was 191KB minified, now 87KB)!
## 1.1.13 (2019-08-08)
### Bug Fixes
......
......@@ -51,11 +51,11 @@ const { patcher, defaults, version } = htmlTablePatcher;
This package has three builds in `dist/` folder:
| Type | Key in `package.json` | Path | Size |
| ------------------------------------------------------------------------------------------------------- | --------------------- | -------------------------------- | ------ |
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/html-table-patcher.cjs.js` | 9 KB |
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/html-table-patcher.esm.js` | 8 KB |
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/html-table-patcher.umd.js` | 191 KB |
| Type | Key in `package.json` | Path | Size |
| ------------------------------------------------------------------------------------------------------- | --------------------- | -------------------------------- | ----- |
| Main export - **CommonJS version**, transpiled to ES5, contains `require` and `module.exports` | `main` | `dist/html-table-patcher.cjs.js` | 8 KB |
| **ES module** build that Webpack/Rollup understands. Untranspiled ES6 code with `import`/`export`. | `module` | `dist/html-table-patcher.esm.js` | 6 KB |
| **UMD build** for browsers, transpiled, minified, containing `iife`'s and has all dependencies baked-in | `browser` | `dist/html-table-patcher.umd.js` | 86 KB |
**[⬆ back to top](#)**
......@@ -179,7 +179,7 @@ Copyright (c) 2015-2020 Roy Revelt and other contributors
[gitlab-img]: https://img.shields.io/badge/repo-on%20GitLab-brightgreen.svg?style=flat-square
[gitlab-url]: https://gitlab.com/codsen/codsen/tree/master/packages/html-table-patcher
[cov-img]: https://img.shields.io/badge/coverage-93.46%25-brightgreen.svg?style=flat-square
[cov-img]: https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square
[cov-url]: https://gitlab.com/codsen/codsen/tree/master/packages/html-table-patcher
[deps2d-img]: https://img.shields.io/badge/deps%20in%202D-see_here-08f0fd.svg?style=flat-square
[deps2d-url]: http://npm.anvaka.com/#/view/2d/html-table-patcher
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -109,11 +109,7 @@
"various": {
"devDependencies": [
"@rollup/plugin-json",
"html-crush",
"object-delete-key",
"rollup-plugin-node-builtins",
"rollup-plugin-node-globals",
"json-stringify-safe"
"rollup-plugin-node-builtins"
],
"travisVersionsOverride": []
}
......@@ -129,10 +125,11 @@
"timeout": 0
},
"dependencies": {
"dom-serializer": "^1.0.1",
"domutils-bastardised": "^1.7.3",
"ast-monkey-traverse-with-lookahead": "^1.1.4",
"codsen-parser": "^0.6.4",
"html-comment-regex": "^1.1.2",
"html-dom-parser": "^0.2.3"
"ranges-apply": "^3.1.7",
"ranges-push": "^3.7.10"
},
"devDependencies": {
"@babel/core": "^7.9.6",
......@@ -143,16 +140,12 @@
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-strip": "^1.3.2",
"benchmark": "^2.1.4",
"html-crush": "^1.9.31",
"json-stringify-safe": "^5.0.1",
"lect": "^0.13.2",
"object-delete-key": "^1.9.25",
"rollup": "^2.8.2",
"rollup": "^2.9.0",
"rollup-plugin-ascii": "^0.0.3",
"rollup-plugin-banner": "^0.2.1",
"rollup-plugin-cleanup": "^3.1.1",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-terser": "^5.3.0",
"tap": "^14.10.7"
}
......
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from "rollup-plugin-terser";
......@@ -32,7 +31,6 @@ export default (commandLineArgs) => {
sourceMap: false,
}),
builtins(),
globals(),
resolve(),
json(),
commonjs(),
......@@ -55,7 +53,6 @@ export default (commandLineArgs) => {
sourceMap: false,
}),
builtins(),
globals(),
resolve(),
json(),
commonjs(),
......@@ -69,17 +66,17 @@ export default (commandLineArgs) => {
input: "src/main.js",
output: [{ file: pkg.main, format: "cjs" }],
external: [
"dom-serializer",
"domutils-bastardised",
"ast-monkey-traverse-with-lookahead",
"codsen-parser",
"html-comment-regex",
"html-dom-parser",
"ranges-apply",
"ranges-push",
],
plugins: [
strip({
sourceMap: false,
}),
builtins(),
globals(),
json(),
babel(),
cleanup({ comments: "istanbul" }),
......@@ -92,17 +89,17 @@ export default (commandLineArgs) => {
input: "src/main.js",
output: [{ file: pkg.module, format: "es" }],
external: [
"dom-serializer",
"domutils-bastardised",
"ast-monkey-traverse-with-lookahead",
"codsen-parser",
"html-comment-regex",
"html-dom-parser",
"ranges-apply",
"ranges-push",
],
plugins: [
strip({
sourceMap: false,
}),
builtins(),
globals(),
json(),
cleanup({ comments: "istanbul" }),
banner(licensePiece),
......
This diff is collapsed.
import tap from "tap";
import { patcher, defaults, version } from "../dist/html-table-patcher.esm";
// checking the API bits
// -----------------------------------------------------------------------------
tap.test(
`01 - ${`\u001b[${34}m${`API bits`}\u001b[${39}m`} - defaults`,
(t) => {
t.ok(typeof defaults === "object", "01.01");
t.ok(Object.keys(defaults).length > 0, "01.02");
t.end();
}
);
tap.test(`02 - ${`\u001b[${34}m${`API bits`}\u001b[${39}m`} - version`, (t) => {
t.match(version, /\d*\.\d*\.\d*/, "02");
t.end();
});
tap.test(
`03 - ${`\u001b[${34}m${`API bits`}\u001b[${39}m`} - patcher()`,
(t) => {
t.is(patcher(1).result, 1, "03.01");
t.is(patcher(false).result, false, "03.02");
t.is(patcher(null).result, null, "03.03");
t.end();
}
);
tap.test(
`04 - ${`\u001b[${34}m${`API bits`}\u001b[${39}m`} - opts.opts.cssStylesContent`,
(t) => {
t.is(
patcher("<a>", {
cssStylesContent: 9,
}).result,
"<a>",
"04.01"
);
t.is(
patcher(false, {
cssStylesContent: "",
}).result,
false,
"04.02"
);
t.is(
patcher(null, {
cssStylesContent: 9,
}).result,
null,
"04.03"
);
t.end();
}
);
import tap from "tap";
import { processThis, tiny } from "./util";
// code between closing TD and closing TR
// -----------------------------------------------------------------------------
tap.test(
`01 - ${`\u001b[${35}m${`type 4`}\u001b[${39}m`}${`\u001b[${33}m${` - code closing TD and closing TR`}\u001b[${39}m`} - two tags`,
(t) => {
t.same(
processThis(`<table>
<tr>
<td>
aaa
</td>
zzz
</tr>
</table>`),
tiny(`<table>
<tr>
<td>
aaa
</td>
</tr>
<tr>
<td>
zzz
</td>
</tr>
</table>`),
"01 - 1 col"
);
t.end();
}
);
import tap from "tap";
import { processThis, tiny } from "./util";
// code between TD and TD
// -----------------------------------------------------------------------------
tap.test(
`01 - ${`\u001b[${33}m${`code between ${`\u001b[${34}m${`TD`}\u001b[${39}m`} ${`\u001b[${33}m${`and`}\u001b[${39}m`} ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}`} - between two TD's`,
(t) => {
t.same(
processThis(`<table>
<tr>
<td>
aaa
</td>
zzz
<td>
bbb
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td>
aaa
</td>
</tr>
<tr>
<td>
zzz
</td>
</tr>
<tr>
<td>
bbb
</td>
</tr>
</table>`),
"01 - str before tr - 1 col"
);
t.end();
}
);
tap.test(
`02 - ${`\u001b[${33}m${`code between ${`\u001b[${34}m${`TD`}\u001b[${39}m`} ${`\u001b[${33}m${`and`}\u001b[${39}m`} ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}`} - 3 places`,
(t) => {
t.is(
processThis(`<table>
<tr>
x
<td>
1
</td>
y
<td>
2
</td>
z
</tr>
</table>`),
tiny(`<table>
<tr>
<td>
x
</td>
</tr>
<tr>
<td>
1
</td>
</tr>
<tr>
<td>
y
</td>
</tr>
<tr>
<td>
2
</td>
</tr>
<tr>
<td>
z
</td>
</tr>
</table>`),
"02"
);
t.end();
}
);
import tap from "tap";
import { processThis, tiny } from "./util";
// 02. type #2 - code between TR and TD
// -----------------------------------------------------------------------------
tap.test(
`01 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - first TD after TR`,
(t) => {
t.same(
processThis(`<table>
<tr>
zzz
<td>
something
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td>
zzz
</td>
</tr>
<tr>
<td>
something
</td>
</tr>
</table>`),
"01 - str before tr - 1 col"
);
t.end();
}
);
tap.test(
`02 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - colspan=2`,
(t) => {
t.same(
processThis(`<table>
<tr>
x
<td>
1
</td>
<td>
2
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td colspan="2">
x
</td>
</tr>
<tr>
<td>
1
</td>
<td>
2
</td>
</tr>
</table>`),
"02 - str before tr - colspan=2"
);
t.end();
}
);
tap.test(
`03 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - align="center", one TD`,
(t) => {
t.same(
processThis(`<table>
<tr>
x
<td align="center">
1
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td align="center">
x
</td>
</tr>
<tr>
<td align="center">
1
</td>
</tr>
</table>`),
"03"
);
t.end();
}
);
tap.test(
`04 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - align="center" on one of two TD's`,
(t) => {
t.same(
processThis(`<table>
<tr>
x
<td align="center">
1
</td>
<td>
2
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td colspan="2">
x
</td>
</tr>
<tr>
<td align="center">
1
</td>
<td>
2
</td>
</tr>
</table>`),
"04"
);
t.end();
}
);
import tap from "tap";
import { processThis, tiny } from "./util";
// false positives
// -----------------------------------------------------------------------------
tap.test(
`01 - ${`\u001b[${36}m${`false positives`}\u001b[${39}m`}${`\u001b[${33}m${` - comments`}\u001b[${39}m`} - tight comments`,
(t) => {
const str = `<!--zzz--><table><!--zzz-->
<tr><!--zzz-->
<td><!--zzz-->
aaa<!--zzz-->
</td><!--zzz-->
<td><!--zzz-->
aaa<!--zzz-->
</td><!--zzz-->
</tr><!--zzz-->
</table><!--zzz-->`;
t.same(processThis(str), tiny(str), "01");
t.end();
}
);
tap.test(
`02 - ${`\u001b[${36}m${`false positives`}\u001b[${39}m`}${`\u001b[${33}m${` - comments`}\u001b[${39}m`} - comments include line breaks`,
(t) => {
const str = `<!--zzz\nyyy--><table><!--zzz\nyyy-->
<tr><!--zzz\nyyy-->
<td><!--zzz\nyyy-->
aaa<!--zzz\nyyy-->
</td><!--zzz\nyyy-->
<td><!--zzz\nyyy-->
aaa<!--zzz\nyyy-->
</td><!--zzz\nyyy-->
</tr><!--zzz\nyyy-->
</table><!--zzz\nyyy-->`;
t.same(processThis(str), tiny(str), "02");
t.end();
}
);
tap.test(
`03 - ${`\u001b[${36}m${`false positives`}\u001b[${39}m`}${`\u001b[${33}m${` - comments`}\u001b[${39}m`} - comments include line breaks`,
(t) => {
const str = `<!--zzz\nyyy--><table><!--zzz\nyyy-->
<tr><!--zzz<table>zzz<tr>yyy-->
<td><!--zzz</td>zzz<td>yyy-->
aaa<!--zzz</td><td>yyy-->
</td><!--zzz</td><td>yyy-->
<td><!--zzz</td><td>yyy-->
aaa<!--zzz</td><td>yyy-->
</td><!--zzz<td></td>yyy-->
</tr><!--zzz<tr></tr><tr></tr><table>zzz</table>yyy-->
</table><!--zzz\nyyy-->`;
t.same(processThis(str), tiny(str), "03");
t.end();
}
);
import { patcher } from "../dist/html-table-patcher.esm";
function processThis(str, opts) {
return tiny(patcher(str, opts).result);
}
function tiny(something) {
if (typeof something !== "string") {
return "";
}
return something.replace(/\s+/g, "");
}
export { processThis, tiny };
import tap from "tap";
import { crush } from "html-crush";
import { patcher, defaults, version } from "../dist/html-table-patcher.esm";
function processThis(str, opts) {
const res =
crush(patcher(str, opts), {
lineLengthLimit: 0,
removeLineBreaks: true,
}).result || "";
return res.replace(/\s*\n\s*/gm, "");
}
function tiny(something) {
return crush(something, {
lineLengthLimit: 0,
removeLineBreaks: true,
}).result.replace(/\s*\n\s*/gm, "");
}
import { processThis, tiny } from "./util";
// 01. type #1 - code between two TR's or TR and TABLE
// this is an easier case than type #2.
......@@ -500,310 +483,3 @@ tap.test(
t.end();
}
);
// 02. type #2 - code between TR and TD
// -----------------------------------------------------------------------------
tap.test(
`15 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - first TD after TR`,
(t) => {
t.same(
processThis(`<table>
<tr>
zzz
<td>
something
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td>
zzz
</td>
</tr>
<tr>
<td>
something
</td>
</tr>
</table>`),
"15 - str before tr - 1 col"
);
t.end();
}
);
tap.test(
`16 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - colspan=2`,
(t) => {
t.same(
processThis(`<table>
<tr>
x
<td>
1
</td>
<td>
2
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td colspan="2">
x
</td>
</tr>
<tr>
<td>
1
</td>
<td>
2
</td>
</tr>
</table>`),
"16 - str before tr - colspan=2"
);
t.end();
}
);
tap.test(
`17 - ${`\u001b[${36}m${`type 2`}\u001b[${39}m`}${`\u001b[${33}m${` - code between TR and ${`\u001b[${34}m${`TD`}\u001b[${39}m`}`}\u001b[${39}m`} - align="center", one TD`,
(t) => {
t.same(
processThis(`<table>
<tr>
x
<td align="center">
1
</td>
</tr>
</table>`),
tiny(`<table>
<tr>
<td align="center">
x
</td>
</tr>
<tr>
<td align="center">
1
</td>
</tr>
</table>`),
"17"
);
t.end();
}
);
tap.test(
`18 - ${`\u001b[${36}