2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-11 18:02:26 +03:00

refactor(*): convert to babel and generation to lib, es, dist folders (#2)

* refactor(*): convert to babel and generation to lib, es, dist

* chore(*): remove generated files

* fix(*): lint run command
This commit is contained in:
Nikolay Kostyurin
2018-09-09 23:55:28 +02:00
committed by GitHub
parent d22a2895a4
commit 32a7fb51da
76 changed files with 930 additions and 10174 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
dist
es
lib
test
rollup.config.js
+3 -1
View File
@@ -1,3 +1,5 @@
package-lock.json
coverage
dist
dist
lib
es
+2 -1
View File
@@ -1,6 +1,7 @@
package-lock.json
coverage
src
dist
!dist
!lib
!es
*.test.js
-1
View File
@@ -1 +0,0 @@
module.exports = require('./parse');
+24 -16
View File
@@ -1,41 +1,46 @@
{
"name": "@bbob/parser",
"version": "1.3.0",
"description": "Fast, flexible, and lean implementation of BBcode parser",
"homepage": "https://github.com/JiLiZART/bbob",
"description": "Just parses BBcode to AST array",
"keywords": [
"bbcode",
"parser",
"fast",
"ast",
"bbcode parser",
"bbcodeparser",
"bbob",
"serializer",
"bbcode serializer",
"bbcode serializer",
"bbcodeserializer",
"parse",
"serialize",
"html"
"array",
"parse"
],
"main": "lib/index.js",
"dependencies": {
"@bbob/plugin-helper": "^1.1.0"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"browser": "dist/index.js",
"browserName": "BbobParser",
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/JiLiZART/bbob/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/JiLiZART/bbob.git"
},
"scripts": {
"build": "../../node_modules/.bin/rollup -c",
"dev": "../../node_modules/.bin/rollup -c -w",
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"test": "../../node_modules/.bin/jest --",
"cover": "../../node_modules/.bin/jest --coverage",
"lint": "../../node_modules/.bin/eslint .",
"size": "../../node_modules/.bin/size-limit"
},
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
"size-limit": [
{
"path": "lib/index.js"
@@ -45,6 +50,9 @@
"registry": "https://registry.npmjs.org/"
},
"files": [
"lib"
"dist",
"lib",
"src",
"es"
]
}
-33
View File
@@ -1,33 +0,0 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import pkg from './package.json';
export default [
// browser-friendly UMD build
{
input: 'lib/index.js',
output: {
name: 'BBobParser',
file: pkg.browser,
format: 'umd',
},
plugins: [
resolve(), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
],
},
// CommonJS (for Node) and ES module (for bundlers) build.
// (We could have three entries in the configuration array
// instead of two, but it's quicker to generate multiple
// builds from a single configuration where possible, using
// an array for the output` option, where we can specify
// `file` and `format` for each target)
{
input: 'lib/index.js',
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' },
],
},
];
@@ -1,9 +1,8 @@
const {
getChar,
import {
OPEN_BRAKET,
CLOSE_BRAKET,
SLASH,
} = require('@bbob/plugin-helper/lib/char');
} from '@bbob/plugin-helper/lib/char';
// type, value, line, row,
const TOKEN_TYPE_ID = 'type'; // 0;
@@ -28,7 +27,7 @@ const isTextToken = token =>
token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
const isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
const isTagEnd = token => getTokenValue(token).charCodeAt(0) === SLASH;
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;
@@ -40,14 +39,14 @@ const getTagName = (token) => {
};
const convertTagToText = (token) => {
let text = getChar(OPEN_BRAKET);
let text = OPEN_BRAKET;
if (isTagEnd(token)) {
text += getChar(SLASH);
text += SLASH;
}
text += getTokenValue(token);
text += getChar(CLOSE_BRAKET);
text += CLOSE_BRAKET;
return text;
};
@@ -109,15 +108,15 @@ class Token {
}
}
module.exports = Token;
module.exports.TYPE_ID = TOKEN_TYPE_ID;
module.exports.VALUE_ID = TOKEN_VALUE_ID;
module.exports.LINE_ID = TOKEN_LINE_ID;
module.exports.COLUMN_ID = TOKEN_COLUMN_ID;
module.exports.TYPE_WORD = TOKEN_TYPE_WORD;
module.exports.TYPE_TAG = TOKEN_TYPE_TAG;
module.exports.TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
module.exports.TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
module.exports.TYPE_SPACE = TOKEN_TYPE_SPACE;
module.exports.TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
export const TYPE_ID = TOKEN_TYPE_ID;
export const VALUE_ID = TOKEN_VALUE_ID;
export const LINE_ID = TOKEN_LINE_ID;
export const COLUMN_ID = TOKEN_COLUMN_ID;
export const TYPE_WORD = TOKEN_TYPE_WORD;
export const TYPE_TAG = TOKEN_TYPE_TAG;
export const TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
export const TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
export const TYPE_SPACE = TOKEN_TYPE_SPACE;
export const TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
export { Token };
export default Token;
+1
View File
@@ -0,0 +1 @@
export { parse, createTagNode } from './parse';
@@ -1,16 +1,17 @@
/* eslint-disable no-plusplus,no-param-reassign */
const c = require('@bbob/plugin-helper/lib/char');
const Token = require('./Token');
import {
OPEN_BRAKET,
CLOSE_BRAKET,
QUOTEMARK,
BACKSLASH,
SLASH,
SPACE,
TAB,
EQ,
N,
} from '@bbob/plugin-helper/lib/char';
const OPEN_BRAKET = c.getChar(c.OPEN_BRAKET);
const CLOSE_BRAKET = c.getChar(c.CLOSE_BRAKET);
const QUOTEMARK = c.getChar(c.QUOTEMARK);
const BACKSLASH = c.getChar(c.BACKSLASH);
const SLASH = c.getChar(c.SLASH);
const SPACE = c.getChar(c.SPACE);
const TAB = c.getChar(c.TAB);
const EQ = c.getChar(c.EQ);
const N = c.getChar(c.N);
import { Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD } from './Token';
const RESERVED_CHARS = [CLOSE_BRAKET, OPEN_BRAKET, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N];
const NOT_CHAR_TOKENS = [OPEN_BRAKET, SPACE, TAB, N];
@@ -111,9 +112,9 @@ function createLexer(buffer, options = {}) {
tagName = attrStr;
} else if (isWhiteSpace(attrCharGrabber.getCurr()) || !attrCharGrabber.hasNext()) {
const escaped = unquote(trimChar(attrStr, QUOTEMARK));
attrTokens.push(createToken(Token.TYPE_ATTR_VALUE, escaped, row, col));
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col));
} else {
attrTokens.push(createToken(Token.TYPE_ATTR_NAME, attrStr, row, col));
attrTokens.push(createToken(TYPE_ATTR_NAME, attrStr, row, col));
}
attrCharGrabber.skip();
@@ -136,37 +137,37 @@ function createLexer(buffer, options = {}) {
col = 0;
row++;
emitToken(createToken(Token.TYPE_NEW_LINE, char, row, col));
emitToken(createToken(TYPE_NEW_LINE, char, row, col));
} else if (isWhiteSpace(char)) {
const str = grabber.grabWhile(isWhiteSpace);
emitToken(createToken(Token.TYPE_SPACE, str, row, col));
emitToken(createToken(TYPE_SPACE, str, row, col));
} else if (char === OPEN_BRAKET) {
const nextChar = grabber.getNext();
grabber.skip(); // skip [
if (isCharReserved(nextChar)) {
emitToken(createToken(Token.TYPE_WORD, char, row, col));
emitToken(createToken(TYPE_WORD, char, row, col));
} else {
const str = grabber.grabWhile(val => val !== CLOSE_BRAKET);
grabber.skip(); // skip ]
if (!(str.indexOf(EQ) > 0) || str[0] === SLASH) {
emitToken(createToken(Token.TYPE_TAG, str, row, col));
emitToken(createToken(TYPE_TAG, str, row, col));
} else {
const parsed = parseAttrs(str);
emitToken(createToken(Token.TYPE_TAG, parsed.tag, row, col));
emitToken(createToken(TYPE_TAG, parsed.tag, row, col));
parsed.attrs.map(emitToken);
}
}
} else if (char === CLOSE_BRAKET) {
grabber.skip();
emitToken(createToken(Token.TYPE_WORD, char, row, col));
emitToken(createToken(TYPE_WORD, char, row, col));
} else if (isCharToken(char)) {
const str = grabber.grabWhile(isCharToken);
emitToken(createToken(Token.TYPE_WORD, str, row, col));
emitToken(createToken(TYPE_WORD, str, row, col));
}
};
@@ -191,5 +192,5 @@ function createLexer(buffer, options = {}) {
};
}
module.exports = createLexer;
module.exports.createTokenOfType = createToken;
export const createTokenOfType = createToken;
export { createLexer };
@@ -1,5 +1,5 @@
const createLexer = require('./lexer');
const TagNode = require('@bbob/plugin-helper/lib/TagNode');
import TagNode from '@bbob/plugin-helper/lib/TagNode';
import { createLexer } from './lexer';
/**
* @private
@@ -227,5 +227,5 @@ const parse = (input, opts = {}) => {
return nodes;
};
module.exports = parse;
module.exports.createTagNode = createTagNode;
export { createTagNode, parse };
export default parse;
+3 -3
View File
@@ -1,5 +1,5 @@
const Token = require('../lib/Token');
const lexer = require('../lib/lexer');
const Token = require('../src/Token');
const { createLexer } = require('../src/lexer');
const TYPE = {
WORD: Token.TYPE_WORD,
@@ -10,7 +10,7 @@ const TYPE = {
NEW_LINE: Token.TYPE_NEW_LINE,
};
const tokenize = input => (lexer(input).tokenize());
const tokenize = input => (createLexer(input).tokenize());
describe('lexer', () => {
const expectOutput = (output, tokens) => {
+1 -1
View File
@@ -1,4 +1,4 @@
const parse = require('../lib/parse');
import { parse } from '../src'
describe('Parser', () => {
test('parse paired tags tokens', () => {
+2 -2
View File
@@ -1,5 +1,5 @@
const render = require('posthtml-render');
const parse = require('../lib');
import {parse} from '../src'
import render from 'posthtml-render'
describe('posthtml-render', () => {