mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-14 18:42:24 +03:00
feat: typescript support (#185)
* feat: initial typescript support * feat: typescript support * feat(plugin-helper): move files to typescript * chore: update lock files * feat: preset types * fix: build * fix: benchmark * fix: remove pnpm cache * fix: bench action * fix: pnpm recursive install * fix: nx cache * fix: lock file * fix: workflows * fix: lerna support in pnpm * fix: pnpm workspace * fix: remove unused files * fix: pnpm lock file * fix: update lerna for support pnpm * fix: lerna bootstrap * fix: rollup build * fix: update nx * fix: build * fix: add nx dep target * fix: remove nx cache * fix: workflow run on push only for master * fix: test workflow run on push only for master * fix: remove parallel for gen types * fix: benchmark * fix: benchmark imports * fix: pnpm * fix: types errors and pnpm * fix: types * fix: types * refactor: parser * fix(parser): tests * fix: preset tests * fix: react types * fix: react type declarations * fix: pnpm lock file * fix: react preset types * fix: lock file * fix: vue2 types * feat: dev container support * fix: types * fix: types * refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts * refactor: types * fix: types * fix: rename gen-types to types * fix: nx build order * fix: nx reset * fix: define nx deps explicit * fix: build * fix: nx * fix: nx order build * fix: nx deps * fix: bbob cli tests * fix: tests * fix: cli tests and import * fix: test cover * fix: cli cover
This commit is contained in:
@@ -2,7 +2,8 @@ import { TagNode } from "../src/index";
|
||||
|
||||
describe('index', () => {
|
||||
test('tag with content and params', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
|
||||
const attrs = {test: 1}
|
||||
const tagNode = TagNode.create('test', attrs, ['Hello']);
|
||||
|
||||
expect(String(tagNode)).toBe('[test test="1"]Hello[/test]');
|
||||
});
|
||||
@@ -1,6 +1,14 @@
|
||||
import { TYPE_ID, VALUE_ID, TYPE_WORD, TYPE_TAG, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_SPACE, TYPE_NEW_LINE} from '../src/Token'
|
||||
import { createLexer } from '../src/lexer'
|
||||
|
||||
declare global {
|
||||
namespace jest {
|
||||
interface Matchers<R> {
|
||||
toBeMantchOutput(expected: Array<unknown>): CustomMatcherResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const TYPE = {
|
||||
WORD: TYPE_WORD,
|
||||
TAG: TYPE_TAG,
|
||||
@@ -10,13 +18,15 @@ const TYPE = {
|
||||
NEW_LINE: TYPE_NEW_LINE,
|
||||
};
|
||||
|
||||
const TYPE_NAMES = Object.fromEntries(Object.keys(TYPE).map(key => [TYPE[key], key]));
|
||||
const TYPE_NAMES = Object.fromEntries(Object.keys(TYPE).map((key: keyof typeof TYPE) => [TYPE[key], key]));
|
||||
|
||||
const tokenize = input => (createLexer(input).tokenize());
|
||||
const tokenizeEscape = input => (createLexer(input, { enableEscapeTags: true }).tokenize());
|
||||
const tokenizeContextFreeTags = (input, tags = []) => (createLexer(input, { contextFreeTags: tags }).tokenize());
|
||||
const tokenize = (input: string) => (createLexer(input).tokenize());
|
||||
const tokenizeEscape = (input: string) => (createLexer(input, { enableEscapeTags: true }).tokenize());
|
||||
const tokenizeContextFreeTags = (input: string, tags: string[] = []) => (createLexer(input, { contextFreeTags: tags }).tokenize());
|
||||
|
||||
describe('lexer', () => {
|
||||
|
||||
|
||||
expect.extend({
|
||||
toBeMantchOutput(tokens, output) {
|
||||
if (tokens.length !== output.length) {
|
||||
@@ -515,7 +525,7 @@ describe('lexer', () => {
|
||||
});
|
||||
|
||||
describe('html', () => {
|
||||
const tokenizeHTML = input => createLexer(input, { openTag: '<', closeTag: '>' }).tokenize();
|
||||
const tokenizeHTML = (input: string) => createLexer(input, { openTag: '<', closeTag: '>' }).tokenize();
|
||||
|
||||
test('normal attributes', () => {
|
||||
const content = `<button id="test0" class="value0" title="value1">class="value0" title="value1"</button>`;
|
||||
@@ -593,9 +603,7 @@ input.buttonred{cursor:hand;font-family:verdana;background:#d12124;color:#fff;he
|
||||
-->
|
||||
</style>`
|
||||
const tokens = tokenizeHTML(content);
|
||||
const output = [];
|
||||
|
||||
expect(tokens).toBeMantchOutput(output);
|
||||
expect(tokens).toBeMantchOutput([]);
|
||||
});
|
||||
|
||||
test.skip('script tag', () => {
|
||||
@@ -606,9 +614,7 @@ input.buttonred{cursor:hand;font-family:verdana;background:#d12124;color:#fff;he
|
||||
//-->
|
||||
</script>`;
|
||||
const tokens = tokenizeHTML(content);
|
||||
const output = [];
|
||||
|
||||
expect(tokens).toBeMantchOutput(output);
|
||||
expect(tokens).toBeMantchOutput([]);
|
||||
})
|
||||
})
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
import { parse } from '../src'
|
||||
import type { TagNodeTree } from "@bbob/plugin-helper";
|
||||
|
||||
describe('Parser', () => {
|
||||
const expectOutput = (ast, output) => {
|
||||
const expectOutput = (ast: TagNodeTree, output: Partial<TagNodeTree>) => {
|
||||
expect(ast).toBeInstanceOf(Array);
|
||||
expect(ast).toEqual(output);
|
||||
};
|
||||
@@ -440,7 +441,7 @@ sdfasdfasdf
|
||||
})
|
||||
|
||||
describe('html', () => {
|
||||
const parseHTML = input => parse(input, { openTag: '<', closeTag: '>' });
|
||||
const parseHTML = (input: string) => parse(input, { openTag: '<', closeTag: '>' });
|
||||
|
||||
test('normal attributes', () => {
|
||||
const content = `<button id="test0" class="value0" title="value1">class="value0" title="value1"</button>`;
|
||||
Reference in New Issue
Block a user