-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: change ts to js * refactor: refactor to use NODE_TYPES * refactor: remove unused code * ci: add refactor types
- Loading branch information
Showing
24 changed files
with
203 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ next-env.d.ts | |
packages/web-linter/out | ||
packages/**/dist | ||
*.tsbuildinfo | ||
packages/parser/types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ packages/website2/.next | |
out | ||
.next | ||
dist | ||
packages/parser/types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module.exports = { | ||
extends: ["eslint:recommended"], | ||
plugins: ["jest", "node"], | ||
parserOptions: { | ||
ecmaVersion: 9, | ||
}, | ||
env: { | ||
node: true, | ||
es6: true, | ||
}, | ||
rules: { | ||
"node/no-unsupported-features/es-builtins": "error", | ||
"node/no-unsupported-features/es-syntax": "error", | ||
"node/no-unsupported-features/node-builtins": "error", | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["*.test.js"], | ||
env: { | ||
"jest/globals": true, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { parseForESLint } = require("./parser"); | ||
const { NODE_TYPES } = require("./node-types"); | ||
|
||
module.exports.parseForESLint = parseForESLint; | ||
module.exports.NODE_TYPES = NODE_TYPES; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { NodeTypes } = require("es-html-parser"); | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
const { Document, ...restNodeTypes } = NodeTypes; | ||
|
||
const NODE_TYPES = { | ||
Program: "Program", | ||
...restNodeTypes, | ||
}; | ||
|
||
module.exports = { | ||
NODE_TYPES, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @typedef {import("./types").ProgramNode} ProgramNode | ||
*/ | ||
const { parse } = require("es-html-parser"); | ||
const { visitorKeys } = require("./visitor-keys"); | ||
const { traverse } = require("./traverse"); | ||
const { NODE_TYPES } = require("./node-types"); | ||
|
||
/** | ||
* @param {string} code | ||
* @returns {ProgramNode} | ||
*/ | ||
module.exports.parseForESLint = function parseForESLint(code) { | ||
const { ast, tokens } = parse(code); | ||
|
||
const programNode = { | ||
type: "Program", | ||
body: ast.children, | ||
loc: ast.loc, | ||
range: ast.range, | ||
tokens: tokens.filter( | ||
(token) => | ||
token.type !== NODE_TYPES.CommentContent && | ||
token.type !== NODE_TYPES.CommentOpen && | ||
token.type !== NODE_TYPES.CommentClose | ||
), | ||
comments: [], | ||
}; | ||
|
||
traverse(programNode, (node) => { | ||
if (node.type === NODE_TYPES.CommentContent) { | ||
programNode.comments.push({ | ||
type: node.type, | ||
range: node.range, | ||
loc: node.loc, | ||
value: node.value, | ||
}); | ||
} | ||
}); | ||
|
||
return { | ||
ast: programNode, | ||
visitorKeys, | ||
scopeManager: null, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @typedef {import("./types").AnyHTMLNode} AnyHTMLNode | ||
*/ | ||
const { visitorKeys } = require("./visitor-keys"); | ||
|
||
/** | ||
* | ||
* @param {AnyHTMLNode} node | ||
* @param {(arg: AnyHTMLNode) => void} visitor | ||
* @returns {void} | ||
*/ | ||
function traverse(node, visitor) { | ||
if (!node) { | ||
return; | ||
} | ||
visitor(node); | ||
const type = node.type; | ||
const keys = visitorKeys[type]; | ||
|
||
if (!keys || keys.length <= 0) { | ||
return; | ||
} | ||
|
||
keys.forEach((key) => { | ||
// @ts-ignore | ||
const value = node[key]; | ||
if (value) { | ||
if (Array.isArray(value)) { | ||
value.forEach((n) => traverse(n, visitor)); | ||
} else { | ||
traverse(value, visitor); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
traverse, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.