Skip to content

Commit

Permalink
Wrap type-only class fields in flow comments (babel#11096)
Browse files Browse the repository at this point in the history
* Wrap type-only class fields in flow comments

* Fix
  • Loading branch information
nicolo-ribaudo authored and rajasekarm committed Feb 17, 2020
1 parent c89392a commit deea971
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -45,6 +45,7 @@ import { ExpressionErrors } from "./util";

export default class ExpressionParser extends LValParser {
// Forward-declaration: defined in statement.js
/*::
+parseBlock: (
allowDirectives?: boolean,
createNewLexicalScope?: boolean,
Expand All @@ -63,6 +64,7 @@ export default class ExpressionParser extends LValParser {
) => T;
+parseFunctionParams: (node: N.Function, allowModifiers?: boolean) => void;
+takeDecorators: (node: N.HasDecorators) => void;
*/

// Check if property __proto__ has been used more than once.
// If the expression is a destructuring assignment, then __proto__ may appear
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-parser/src/parser/index.js
@@ -1,7 +1,7 @@
// @flow

import type { Options } from "../options";
import type { File, JSXOpeningElement } from "../types";
import type { File /*::, JSXOpeningElement */ } from "../types";
import type { PluginList } from "../plugin-utils";
import { getOptions } from "../options";
import StatementParser from "./statement";
Expand All @@ -13,9 +13,11 @@ export type PluginsMap = Map<string, { [string]: any }>;

export default class Parser extends StatementParser {
// Forward-declaration so typescript plugin can override jsx plugin
/*::
+jsxParseOpeningElementAfterName: (
node: JSXOpeningElement,
) => JSXOpeningElement;
*/

constructor(options: ?Options, input: string) {
options = getOptions(options);
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-parser/src/parser/location.js
Expand Up @@ -10,7 +10,10 @@ import CommentsParser from "./comments";
// message.

export default class LocationParser extends CommentsParser {
// Forward-declaration: defined in tokenizer/index.js
/*::
+isLookahead: boolean;
*/

getLocationForPosition(pos: number): Position {
let loc;
Expand Down
10 changes: 7 additions & 3 deletions packages/babel-parser/src/parser/lval.js
Expand Up @@ -6,13 +6,13 @@ import type {
TSParameterProperty,
Decorator,
Expression,
Identifier,
Node,
ObjectExpression,
ObjectPattern,
Pattern,
RestElement,
SpreadElement,
/*:: Identifier, */
/*:: ObjectExpression, */
/*:: ObjectPattern, */
} from "../types";
import type { Pos, Position } from "../util/location";
import {
Expand All @@ -31,6 +31,7 @@ const unwrapParenthesizedExpression = (node: Node) => {

export default class LValParser extends NodeUtils {
// Forward-declaration: defined in expression.js
/*::
+parseIdentifier: (liberal?: boolean) => Identifier;
+parseMaybeAssign: (
noIn?: ?boolean,
Expand All @@ -42,8 +43,11 @@ export default class LValParser extends NodeUtils {
isPattern: boolean,
refExpressionErrors?: ?ExpressionErrors,
) => T;
*/
// Forward-declaration: defined in statement.js
/*::
+parseDecorator: () => Decorator;
*/

// Convert existing expression atom to assignable pattern
// if possible.
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -111,7 +111,9 @@ export class Token {
export default class Tokenizer extends LocationParser {
// Forward-declarations
// parser/util.js
/*::
+unexpected: (pos?: ?number, messageOrType?: string | TokenType) => empty;
*/

isLookahead: boolean;

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/util/scope.js
Expand Up @@ -92,7 +92,7 @@ export default class ScopeHandler<IScope: Scope = Scope> {
return new Scope(flags);
}
// This method will be overwritten by subclasses
+createScope: (flags: ScopeFlags) => IScope;
/*:: +createScope: (flags: ScopeFlags) => IScope; */

enter(flags: ScopeFlags) {
this.scopeStack.push(this.createScope(flags));
Expand Down

0 comments on commit deea971

Please sign in to comment.