Skip to content

Commit

Permalink
refactor(node): allow require and import on dom.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
Masquerade-Circus committed Sep 27, 2020
1 parent 2748341 commit f7cb19a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"scripts": {
"dev:source": "cross-env NODE_ENV=development node rollupSource.js",
"dev:scratchpad": "cross-env NODE_ENV=development nodemon -w ./test -w ./lib -w ./plugins -w ./scratchpad.js --exec 'mocha --timeout 10000 --slow 0 --require @babel/register --require esm \"scratchpad.js\"'",
"dev:test": "cross-env NODE_ENV=development nodemon -w ./test -w ./lib -w ./plugins --exec 'mocha --bail --timeout 10000 --slow 0 --require @babel/register --require esm \"test/**/*_test.js\"'",
"dev:test:nyc": "cross-env NODE_ENV=development nodemon -w ./test -w ./lib -w ./plugins --exec 'nyc --reporter=text --reporter=lcov mocha --timeout 10000 --slow 0 --require @babel/register --require esm \"test/**/*_test.js\"'",
"dev:test": "cross-env NODE_ENV=development nodemon -w ./test -w ./lib -w ./plugins --exec 'mocha --bail --timeout 10000 --slow 0 --require @babel/register \"test/**/*_test.js\"'",
"dev:test:nyc": "cross-env NODE_ENV=development nodemon -w ./test -w ./lib -w ./plugins --exec 'nyc --reporter=text --reporter=lcov mocha --timeout 10000 --slow 0 --require @babel/register \"test/**/*_test.js\"'",
"build": "yarn build:source && yarn remark",
"build:source": "cross-env NODE_ENV=production node rollupSource.js",
"test": "cross-env NODE_ENV=development nyc mocha --timeout 10000 --require @babel/register --require esm \"test/**/*_test.js\"",
"test": "cross-env NODE_ENV=development nyc mocha --timeout 10000 --require @babel/register \"test/**/*_test.js\"",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"remark": "remark . -o",
"commit": "git add . && git-cz",
Expand Down Expand Up @@ -70,7 +70,6 @@
"dayjs": "^1.8.36",
"eslint": "^7.9.0",
"eslint-plugin-sonarjs": "^0.5.0",
"esm": "^3.2.25",
"expect": "^26.4.2",
"faker": "^5.1.0",
"micro": "^9.3.4",
Expand Down
22 changes: 14 additions & 8 deletions plugins/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
let parse5 = require('parse5');
'use strict';

export function parseAttributes(attributes) {
const parse5 = require('parse5');

const parseAttributes = exports.parseAttributes = function (attributes) {
let attrs = [];
for (let i = 0, l = attributes.length; i < l; i++) {
attrs.push({
Expand All @@ -9,9 +11,9 @@ export function parseAttributes(attributes) {
});
}
return attrs;
}
};

export function parseHtml(html, options = {}) {
const parseHtml = exports.parseHtml = function (html, options = {}) {
let returnHtml = /^<!DOCTYPE/i.test(html) || /^<html(\s|>)/i.test(html);
let returnBody = /^<body(\s|>)/i.test(html);
let returnHead = /^<head(\s|>)/i.test(html);
Expand All @@ -33,7 +35,7 @@ export function parseHtml(html, options = {}) {
}

return parse5.parseFragment(html, options).childNodes;
}
};

function generateDom(tree) {
let childNodes = [];
Expand Down Expand Up @@ -173,8 +175,9 @@ class Node {
}
}
}
exports.Node = Node;

export class Text extends Node {
class Text extends Node {
constructor(text) {
super(3, '#text');
this.textContent = text;
Expand All @@ -186,8 +189,9 @@ export class Text extends Node {
return this.nodeValue;
}
}
exports.Text = Text;

export class Element extends Node {
class Element extends Node {
constructor(nodeType, nodeName) {
super(nodeType || 1, nodeName);
this.attributes = [];
Expand Down Expand Up @@ -317,8 +321,9 @@ export class Element extends Node {
return serialize(this);
}
}
exports.Element = Element;

export class Document extends Element {
class Document extends Element {
constructor() {
super(9, '#document');
}
Expand All @@ -337,3 +342,4 @@ export class Document extends Element {
return new Text(text);
}
}
exports.Document = Document;
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4061,11 +4061,6 @@ eslint@^7.9.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

esm@^3.2.25:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==

espree@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-7.3.0.tgz#dc30437cf67947cf576121ebd780f15eeac72348"
Expand Down

0 comments on commit f7cb19a

Please sign in to comment.