From 5208afc54128a2514688cc11d0d5aa9bfe75ed2c Mon Sep 17 00:00:00 2001 From: Pieter Vanderwerff Date: Wed, 6 Sep 2023 11:30:08 -0700 Subject: [PATCH] Default enableExperimentalComponentSyntax on Summary: With the change to unreserve the `component` keyword in type contexts (D48710156) there is now no additional errors introduced by using `enableExperimentalComponentSyntax` so lets default it on to make the rollout easier. Reviewed By: jbrown215 Differential Revision: D48710417 fbshipit-source-id: c7888ef583a30a2db345b53cfb75a83d09b72b31 --- .../__tests__/hermes-scope/component-test.js | 10 +--------- tools/hermes-parser/js/hermes-eslint/src/index.js | 2 +- .../js/hermes-eslint/src/scope-manager/analyze.js | 2 ++ .../js/hermes-parser/__test_utils__/parse.js | 4 ++-- .../__tests__/ComponentDeclaration-test.js | 9 ++++----- .../__tests__/ComponentTypeAnnotation-test.js | 6 ++---- .../__tests__/ConditionalTypeAnnotation-test.js | 9 ++++----- .../hermes-parser/__tests__/DeclareComponent-test.js | 6 ++---- .../js/hermes-parser/__tests__/HermesParser-test.js | 8 ++++---- .../js/hermes-parser/__tests__/TypeOperator-test.js | 9 ++++----- tools/hermes-parser/js/hermes-parser/src/index.js | 4 ++++ 11 files changed, 30 insertions(+), 39 deletions(-) diff --git a/tools/hermes-parser/js/hermes-eslint/__tests__/hermes-scope/component-test.js b/tools/hermes-parser/js/hermes-eslint/__tests__/hermes-scope/component-test.js index e913368c69d..4499e3324db 100644 --- a/tools/hermes-parser/js/hermes-eslint/__tests__/hermes-scope/component-test.js +++ b/tools/hermes-parser/js/hermes-eslint/__tests__/hermes-scope/component-test.js @@ -10,16 +10,8 @@ 'use strict'; -import type {ParseForESLintReturn} from '../../src'; - import {DefinitionType, ScopeType} from '../../src'; -import {parseForESLint as parseForESLintWithOptions} from '../../src'; - -function parseForESLint(str: string): ParseForESLintReturn { - return parseForESLintWithOptions(str, { - enableExperimentalComponentSyntax: true, - }); -} +import {parseForESLint} from '../../src'; describe('Component', () => { describe('Declaration', () => { diff --git a/tools/hermes-parser/js/hermes-eslint/src/index.js b/tools/hermes-parser/js/hermes-eslint/src/index.js index 4dfde222a13..a8b717727c4 100644 --- a/tools/hermes-parser/js/hermes-eslint/src/index.js +++ b/tools/hermes-parser/js/hermes-eslint/src/index.js @@ -28,7 +28,7 @@ function parse(code: string, options?: ParseForESLintOptions): Program { sourceType: options?.sourceType ?? 'module', tokens: true, enableExperimentalComponentSyntax: - options?.enableExperimentalComponentSyntax ?? false, + options?.enableExperimentalComponentSyntax ?? true, }; try { diff --git a/tools/hermes-parser/js/hermes-eslint/src/scope-manager/analyze.js b/tools/hermes-parser/js/hermes-eslint/src/scope-manager/analyze.js index 32d679bdfa6..f781c2c3af5 100644 --- a/tools/hermes-parser/js/hermes-eslint/src/scope-manager/analyze.js +++ b/tools/hermes-parser/js/hermes-eslint/src/scope-manager/analyze.js @@ -57,6 +57,8 @@ type AnalyzeOptions = $ReadOnly<{ /** * Support experimental component syntax + * + * Defaults to `true`. */ enableExperimentalComponentSyntax?: boolean, }>; diff --git a/tools/hermes-parser/js/hermes-parser/__test_utils__/parse.js b/tools/hermes-parser/js/hermes-parser/__test_utils__/parse.js index 286f67185db..2971f9a0e57 100644 --- a/tools/hermes-parser/js/hermes-parser/__test_utils__/parse.js +++ b/tools/hermes-parser/js/hermes-parser/__test_utils__/parse.js @@ -73,7 +73,7 @@ export function parseForSnapshot( ): mixed { const parseOpts = { enableExperimentalComponentSyntax: - enableExperimentalComponentSyntax ?? false, + enableExperimentalComponentSyntax ?? true, }; if (babel === true) { return cleanASTForSnapshot( @@ -103,7 +103,7 @@ export async function printForSnapshot( ): Promise { const parseOpts = { enableExperimentalComponentSyntax: - enableExperimentalComponentSyntax ?? false, + enableExperimentalComponentSyntax ?? true, }; if (babel === true) { const ast = parse(source, { diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/ComponentDeclaration-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/ComponentDeclaration-test.js index 0f5c65ef8b3..fbd05eeceb0 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/ComponentDeclaration-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/ComponentDeclaration-test.js @@ -10,18 +10,17 @@ import {parseForSnapshot, printForSnapshot} from '../__test_utils__/parse'; -const parserOpts = {enableExperimentalComponentSyntax: true}; async function printForSnapshotESTree(code: string) { - return printForSnapshot(code, parserOpts); + return printForSnapshot(code); } async function parseForSnapshotESTree(code: string) { - return parseForSnapshot(code, parserOpts); + return parseForSnapshot(code); } async function printForSnapshotBabel(code: string) { - return printForSnapshot(code, {babel: true, ...parserOpts}); + return printForSnapshot(code, {babel: true}); } async function parseForSnapshotBabel(code: string) { - return parseForSnapshot(code, {babel: true, ...parserOpts}); + return parseForSnapshot(code, {babel: true}); } describe('ComponentDeclaration', () => { diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/ComponentTypeAnnotation-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/ComponentTypeAnnotation-test.js index e842bcaa057..ee6c22b9625 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/ComponentTypeAnnotation-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/ComponentTypeAnnotation-test.js @@ -16,8 +16,6 @@ import { } from '../__test_utils__/alignment-utils'; import {parseForSnapshot} from '../__test_utils__/parse'; -const parserOpts = {enableExperimentalComponentSyntax: true}; - describe('ComponentTypeAnnotation', () => { const testCase: AlignmentCase = { code: ` @@ -34,7 +32,7 @@ describe('ComponentTypeAnnotation', () => { }; test('ESTree', () => { - expect(parseForSnapshot(testCase.code, parserOpts)).toMatchInlineSnapshot(` + expect(parseForSnapshot(testCase.code)).toMatchInlineSnapshot(` { "body": [ { @@ -62,7 +60,7 @@ describe('ComponentTypeAnnotation', () => { }); test('Babel', () => { - expect(parseForSnapshot(testCase.code, {babel: true, ...parserOpts})) + expect(parseForSnapshot(testCase.code, {babel: true})) .toMatchInlineSnapshot(` { "body": [ diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/ConditionalTypeAnnotation-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/ConditionalTypeAnnotation-test.js index a782b04e72d..d1611c6e6d7 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/ConditionalTypeAnnotation-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/ConditionalTypeAnnotation-test.js @@ -10,18 +10,17 @@ import {parseForSnapshot, printForSnapshot} from '../__test_utils__/parse'; -const parserOpts = {enableExperimentalComponentSyntax: true}; async function printForSnapshotESTree(code: string) { - return printForSnapshot(code, parserOpts); + return printForSnapshot(code); } async function parseForSnapshotESTree(code: string) { - return parseForSnapshot(code, parserOpts); + return parseForSnapshot(code); } async function printForSnapshotBabel(code: string) { - return printForSnapshot(code, {babel: true, ...parserOpts}); + return printForSnapshot(code, {babel: true}); } async function parseForSnapshotBabel(code: string) { - return parseForSnapshot(code, {babel: true, ...parserOpts}); + return parseForSnapshot(code, {babel: true}); } describe('ConditionalTypeAnnotation', () => { diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/DeclareComponent-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/DeclareComponent-test.js index 9a9fd48ad21..5290a5b3874 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/DeclareComponent-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/DeclareComponent-test.js @@ -16,8 +16,6 @@ import { } from '../__test_utils__/alignment-utils'; import {parseForSnapshot} from '../__test_utils__/parse'; -const parserOpts = {enableExperimentalComponentSyntax: true}; - describe('DeclareComponent', () => { const testCase: AlignmentCase = { code: ` @@ -34,7 +32,7 @@ describe('DeclareComponent', () => { }; test('ESTree', () => { - expect(parseForSnapshot(testCase.code, parserOpts)).toMatchInlineSnapshot(` + expect(parseForSnapshot(testCase.code)).toMatchInlineSnapshot(` { "body": [ { @@ -58,7 +56,7 @@ describe('DeclareComponent', () => { }); test('Babel', () => { - expect(parseForSnapshot(testCase.code, {babel: true, ...parserOpts})) + expect(parseForSnapshot(testCase.code, {babel: true})) .toMatchInlineSnapshot(` { "body": [ diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/HermesParser-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/HermesParser-test.js index e90f7d272ce..2f885b1d1b4 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/HermesParser-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/HermesParser-test.js @@ -198,7 +198,9 @@ return 1 }); test('Allow component syntax', () => { - expect(() => parse('component Foo() {}')).toThrow( + expect(() => + parse('component Foo() {}', {enableExperimentalComponentSyntax: false}), + ).toThrow( new SyntaxError( `';' expected (1:10) component Foo() {} @@ -206,9 +208,7 @@ component Foo() {} ), ); - expect( - parse('component Foo() {}', {enableExperimentalComponentSyntax: true}), - ).toMatchObject({ + expect(parse('component Foo() {}')).toMatchObject({ type: 'Program', body: [ { diff --git a/tools/hermes-parser/js/hermes-parser/__tests__/TypeOperator-test.js b/tools/hermes-parser/js/hermes-parser/__tests__/TypeOperator-test.js index b191a6b4f78..53a80917d9c 100644 --- a/tools/hermes-parser/js/hermes-parser/__tests__/TypeOperator-test.js +++ b/tools/hermes-parser/js/hermes-parser/__tests__/TypeOperator-test.js @@ -10,18 +10,17 @@ import {parseForSnapshot, printForSnapshot} from '../__test_utils__/parse'; -const parserOpts = {enableExperimentalComponentSyntax: true}; async function printForSnapshotESTree(code: string) { - return printForSnapshot(code, parserOpts); + return printForSnapshot(code); } async function parseForSnapshotESTree(code: string) { - return parseForSnapshot(code, parserOpts); + return parseForSnapshot(code); } async function printForSnapshotBabel(code: string) { - return printForSnapshot(code, {babel: true, ...parserOpts}); + return printForSnapshot(code, {babel: true}); } async function parseForSnapshotBabel(code: string) { - return parseForSnapshot(code, {babel: true, ...parserOpts}); + return parseForSnapshot(code, {babel: true}); } describe('TypeOperator', () => { diff --git a/tools/hermes-parser/js/hermes-parser/src/index.js b/tools/hermes-parser/js/hermes-parser/src/index.js index b501286d61f..279bedd7a32 100644 --- a/tools/hermes-parser/js/hermes-parser/src/index.js +++ b/tools/hermes-parser/js/hermes-parser/src/index.js @@ -47,6 +47,10 @@ function getOptions(options?: ParserOptions = {...DEFAULTS}) { ); } + if (options.enableExperimentalComponentSyntax == null) { + options.enableExperimentalComponentSyntax = true; // Enable by default + } + options.tokens = options.tokens === true; options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true;