-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…8984) * Fix: don't use `node.start`/`node.end` (refs #8956) * Docs: clarify AST (fixes #8956) * Docs: fix list style in markdown * Fix: make it rising errors * Docs: add about `Literal#raw` property * fix for review.
- Loading branch information
1 parent
62911e4
commit b3e4598
Showing
12 changed files
with
118 additions
and
15 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
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
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,48 @@ | ||
/** | ||
* @author Toru Nagashima <https://github.com/mysticatea> | ||
*/ | ||
"use strict"; | ||
|
||
const espree = require("espree"); | ||
const Traverser = require("../util/traverser"); | ||
|
||
/** | ||
* Define `start`/`end` properties as throwing error. | ||
* @param {ASTNode} node The node to define. | ||
* @returns {void} | ||
*/ | ||
function defineStartEndAsError(node) { | ||
Object.defineProperty(node, "start", { | ||
get() { | ||
throw new Error("Use node.range[0] instead of node.start"); | ||
}, | ||
configurable: true, | ||
enumerable: false | ||
}); | ||
Object.defineProperty(node, "end", { | ||
get() { | ||
throw new Error("Use node.range[1] instead of node.end"); | ||
}, | ||
configurable: true, | ||
enumerable: false | ||
}); | ||
} | ||
|
||
/** | ||
* Define `start`/`end` properties of all nodes of the given AST as throwing error. | ||
* @param {ASTNode} ast The root node to errorize `start`/`end` properties. | ||
* @returns {void} | ||
*/ | ||
function defineStartEndAsErrorInTree(ast) { | ||
new Traverser().traverse(ast, { enter: defineStartEndAsError }); | ||
ast.tokens.forEach(defineStartEndAsError); | ||
ast.comments.forEach(defineStartEndAsError); | ||
} | ||
|
||
module.exports.parse = (code, options) => { | ||
const ret = espree.parse(code, options); | ||
|
||
defineStartEndAsErrorInTree(ret.ast || ret); | ||
|
||
return ret; | ||
}; |
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,20 @@ | ||
/** | ||
* @author Toru Nagashima <https://github.com/mysticatea> | ||
* | ||
* This file must be loaded before rule files. | ||
* | ||
* This file configures the default config of RuleTester to use TestParser | ||
* instead of espree. The TestParser parses the given source code by espree, | ||
* then remove the `start` and `end` properties of nodes, tokens, and comments. | ||
* | ||
* We have not endorsed that the properties exist on the AST of custom parsers, | ||
* so we should check that core rules don't use the properties. | ||
*/ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const RuleTester = require("../../../lib/testers/rule-tester"); | ||
|
||
RuleTester.setDefaultConfig({ | ||
parser: path.resolve(__dirname, "../../../lib/testers/test-parser") | ||
}); |