Skip to content

Commit

Permalink
Add optional chaining operator support to Babel
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Dec 18, 2020
1 parent 85b42e3 commit ab8f9ba
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
5 changes: 4 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ module.exports = {
"@babel/preset-react",
"@babel/preset-typescript"
],
plugins: ["@babel/plugin-proposal-export-namespace-from"]
plugins: [
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-optional-chaining"
]
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {
"@babel/core": "^7.10.4",
"@babel/plugin-proposal-export-namespace-from": "^7.10.4",
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.12.7",
Expand All @@ -38,8 +39,8 @@
"@types/react-dom": "^17.0.0",
"@types/react-test-renderer": "^17.0.0",
"@types/retry": "^0.12.0",
"@types/ssri": "^7.1.0",
"@types/semver": "^7.3.4",
"@types/ssri": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"babel-eslint": "10.x",
Expand Down
22 changes: 0 additions & 22 deletions packages/core/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@ import styles from "./rollup/styles";
*/
export const entryExts = [".js", ".jsx", ".ts", ".tsx"];

export function isEntryFile(filename: string): boolean {
return entryExts.includes(path.extname(filename));
}

/**
* All file extensions we support for route modules.
*/
export const moduleExts = [".md", ".mdx", ".js", ".jsx", ".ts", ".tsx"];

export function isModuleFile(filename: string): boolean {
return moduleExts.includes(path.extname(filename));
}

/**
* All file extensions we support for styles.
*/
export const stylesExts = [".css"];

export function isStylesFile(filename: string): boolean {
return stylesExts.includes(path.extname(filename));
}

/**
* Runs the build.
*/
Expand Down
10 changes: 10 additions & 0 deletions packages/core/rollup/routeModules.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path";
import type { Plugin } from "rollup";

import { BuildTarget } from "../build";
Expand All @@ -6,6 +7,15 @@ interface RollupObjectInput {
[inputAlias: string]: string;
}

/**
* All file extensions we support for route modules.
*/
export const moduleExts = [".md", ".mdx", ".js", ".jsx", ".ts", ".tsx"];

export function isModuleFile(filename: string): boolean {
return moduleExts.includes(path.extname(filename));
}

export interface RouteModuleFiles {
[routeId: string]: string;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/core/rollup/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { promises as fsp } from "fs";
import path from "path";
import type { Plugin } from "rollup";

import { isStylesFile } from "../routesConvention";
/**
* All file extensions we support for styles.
*/
export const stylesExts = [".css"];

export function isStylesFile(filename: string): boolean {
return stylesExts.includes(path.extname(filename));
}

export function loadStyles(file: string): Promise<string> {
// TODO: Transform using PostCSS based on file extension.
Expand Down
3 changes: 1 addition & 2 deletions packages/core/rollup/watchStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { Plugin } from "rollup";
import chokidar from "chokidar";
import tmp from "tmp";

import { isStylesFile } from "../routesConvention";
import { loadStyles } from "./styles";
import { isStylesFile, loadStyles } from "./styles";

function relname(file: string): string {
return path.relative(process.cwd(), file);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/routesConvention.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from "fs";
import path from "path";

import { isModuleFile, isStylesFile } from "./compiler";
import type { ConfigRouteObject, DefineRoute } from "./routes";
import { defineRoutes, createRouteId } from "./routes";
import { isModuleFile } from "./rollup/routeModules";
import { isStylesFile } from "./rollup/styles";
import invariant from "./invariant";

/**
Expand Down

0 comments on commit ab8f9ba

Please sign in to comment.