Skip to content

Commit

Permalink
Default enableExperimentalComponentSyntax on
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pieterv authored and facebook-github-bot committed Sep 6, 2023
1 parent 6c52c0f commit 5208afc
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion tools/hermes-parser/js/hermes-eslint/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type AnalyzeOptions = $ReadOnly<{

/**
* Support experimental component syntax
*
* Defaults to `true`.
*/
enableExperimentalComponentSyntax?: boolean,
}>;
Expand Down
4 changes: 2 additions & 2 deletions tools/hermes-parser/js/hermes-parser/__test_utils__/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function parseForSnapshot(
): mixed {
const parseOpts = {
enableExperimentalComponentSyntax:
enableExperimentalComponentSyntax ?? false,
enableExperimentalComponentSyntax ?? true,
};
if (babel === true) {
return cleanASTForSnapshot(
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function printForSnapshot(
): Promise<string> {
const parseOpts = {
enableExperimentalComponentSyntax:
enableExperimentalComponentSyntax ?? false,
enableExperimentalComponentSyntax ?? true,
};
if (babel === true) {
const ast = parse(source, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand All @@ -34,7 +32,7 @@ describe('ComponentTypeAnnotation', () => {
};

test('ESTree', () => {
expect(parseForSnapshot(testCase.code, parserOpts)).toMatchInlineSnapshot(`
expect(parseForSnapshot(testCase.code)).toMatchInlineSnapshot(`
{
"body": [
{
Expand Down Expand Up @@ -62,7 +60,7 @@ describe('ComponentTypeAnnotation', () => {
});

test('Babel', () => {
expect(parseForSnapshot(testCase.code, {babel: true, ...parserOpts}))
expect(parseForSnapshot(testCase.code, {babel: true}))
.toMatchInlineSnapshot(`
{
"body": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand All @@ -34,7 +32,7 @@ describe('DeclareComponent', () => {
};

test('ESTree', () => {
expect(parseForSnapshot(testCase.code, parserOpts)).toMatchInlineSnapshot(`
expect(parseForSnapshot(testCase.code)).toMatchInlineSnapshot(`
{
"body": [
{
Expand All @@ -58,7 +56,7 @@ describe('DeclareComponent', () => {
});

test('Babel', () => {
expect(parseForSnapshot(testCase.code, {babel: true, ...parserOpts}))
expect(parseForSnapshot(testCase.code, {babel: true}))
.toMatchInlineSnapshot(`
{
"body": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,17 @@ 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() {}
^`,
),
);

expect(
parse('component Foo() {}', {enableExperimentalComponentSyntax: true}),
).toMatchObject({
expect(parse('component Foo() {}')).toMatchObject({
type: 'Program',
body: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions tools/hermes-parser/js/hermes-parser/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5208afc

Please sign in to comment.