Conversation
| Terminatorless: | ||
| "A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.", | ||
| UnaryLike: "A cover of UnaryExpression and SpreadElement.", | ||
| UserWhitespacable: "", |
There was a problem hiding this comment.
I have no idea what is our intention for UserWhitespacable, it covers
ObjectMethod
ObjectProperty
ObjectTypeInternalSlot
ObjectTypeCallProperty
ObjectTypeIndexer
ObjectTypeProperty
ObjectTypeSpreadProperty
There was a problem hiding this comment.
b1fe449 based on this, it's probably something that used to be used in generator, we can probably just remove it honestly. Sounds like it wasn't intended to be used as a visitor at least but to check something for printing. It would be really odd if someone used it, we don't anywhere?
There was a problem hiding this comment.
Thanks! I update description to "deprecated".
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45208/ |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e8ebe57:
|
| "A cover of functions and [method](#method)s, the must have `body` and `params`. Note: `Function` is different to `FunctionParent`.", | ||
| FunctionParent: | ||
| "A cover of AST nodes that start an execution context with new [VariableEnvironment](https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts). In other words, they define the scope of `var` declarations. FunctionParent did not include `Program` since Babel 7.", | ||
| Immutable: "A cover of immutable AST nodes.", |
There was a problem hiding this comment.
Can we come up with a formal definition of Immutable? What is the difference between Pureish and Immutable?
There was a problem hiding this comment.
I think the original intention was
Immutable-> You cannot define properties on it (+ JSX elements which behave as you can't otherwise you break JSX libraries)Pureish-> It doesn't have side effects
We will probably need to audit all these aliases before Babel 8.
There was a problem hiding this comment.
Thanks! It looks like Immutable refers to https://tc39.es/ecma262/#immutable-prototype-exotic-object ?
| EnumBody: | ||
| "A cover of enum bodies defined in [TypeScript](https://www.typescriptlang.org/docs/handbook/enums.html) and Flow.", | ||
| EnumMember: | ||
| "A cover of enum membors defined in [TypeScript](https://www.typescriptlang.org/docs/handbook/enums.html) and Flow.", |
There was a problem hiding this comment.
I think those are only for Flow
| Function: | ||
| "A cover of functions and [method](#method)s, the must have `body` and `params`. Note: `Function` is different to `FunctionParent`.", | ||
| FunctionParent: | ||
| "A cover of AST nodes that start an execution context with new [VariableEnvironment](https://tc39.es/ecma262/#table-additional-state-components-for-ecmascript-code-execution-contexts). In other words, they define the scope of `var` declarations. FunctionParent did not include `Program` since Babel 7.", |
There was a problem hiding this comment.
Based on the definition, I think it should also cover StaticBlock, which does define a new var scope. Note that in Babel 6 FunctionParent includes Program, but we removed Program in #5923 because the name FunctionParent strongly indicates that it should always be a Function, which is not the case for StaticBlock and Program.
Currently FunctionParent and Function are equivalent, they include exactly the same AST nodes.
BTW we have several usage of scope.getFunctionParent() || scope.getProgramParent(). This depends on the assumption that an AST tree can only have one Program node and all the function node must placed within that program node. This is not true for module-blocks proposal.
There was a problem hiding this comment.
In Babel 8 we might just rename them to LexicalScope and VariableScope, where VariableScope is a subset of LexicalScope.
This is not true for
module-blocksproposal.
Can you show an example where scope.getFunctionParent() || scope.getProgramParent() would break with the module-blocks proposal? When I proposed to use Program for the ModuleExpression node it was exactly to support this existing pattern.
There was a problem hiding this comment.
Ah I missed that module blocks can only be at the top level.
There was a problem hiding this comment.
No, they can also be nested, but we'll want to consider "the top level" the module block itself.
For example, if we have
let mod = module {
class A {}
};We want to get this:
let mod = module {
function _classCallCheck() {}
let A = function A() {
_classCallCheck(this);
};
};and not this:
function _classCallCheck() {}
let mod = module {
let A = function A() {
_classCallCheck(this);
};
};There was a problem hiding this comment.
Yeah, I just checked module blocks proposal and you are right they can be nested.
Can you show an example where
scope.getFunctionParent() || scope.getProgramParent()would break with the module-blocks proposal
function f() {
(module {
var x;
})
}scope.getFunctionParent() || scope.getProgramParent() on var x will return function f instead of the module block.
| TSType: "A cover of TypeScript type annotations.", | ||
| TSTypeElement: "A cover of TypeScript type declarations.", | ||
| Terminatorless: | ||
| "A cover of AST nodes whose semantic will change when a line terminator is inserted between the operator and the operand.", |
There was a problem hiding this comment.
This description isn't true for await and throw, but I don't know what a better description would be 🤷
There was a problem hiding this comment.
I can't find the usage in our codebase. The term terminatorless is referenced in
babel/packages/babel-generator/src/printer.ts
Lines 332 to 348 in d24bd7c
Based on that I don't think ThrowStatement and AwaitExpression should belong to TerminatorLess, we can also consider just remove it.
| Expression: | ||
| "A cover of any [Expression](https://tc39.es/ecma262/#sec-ecmascript-language-expressions)s.", | ||
| ExpressionWrapper: | ||
| "A wrapper of expression that does not have run semantics.", |
There was a problem hiding this comment.
Currently ExpressionWrapper includes
ExpressionStatement
ParenthesizedExpression
TypeCastExpression
We have a very similar helper for the same purpose:
this helper is used in optional chaining to stick chains separated by such transparent wrappers. Since an ExpressionStatement can not be nested inside expression, I think it is safe to merge these two, in other words we can consider to extend ExpressionWrapper to cover TSNonNullExpression, TSAsExpression and TSTypeAssertion.
There was a problem hiding this comment.
We can either merge them, or just delete ExpressionWrapper and replace it with TransparentExpressionWrapper (which has the property that they don't modify the this context for call),
| const aliasDescriptions = { | ||
| Binary: | ||
| "A cover of BinaryExpression and LogicalExpression, which share the same AST shape.", | ||
| Block: "A cover of BlockStatement and its alike.", |
There was a problem hiding this comment.
Block is not used by our codes. I am not sure about its intention.
There was a problem hiding this comment.
Let's just remove it in Babel 8
e23b5ba to
e8ebe57
Compare
|
Merging as-is since it is a docs generator script and not published to npm. |
This PR adds a new "Alias" section to the docs of
@babel/types. It reflects my understanding of current aliases, feedbacks are welcome!This PR includes commits from #13148, will rebase once that one is merged.
See here for rendered results.