Skip to content

Commit

Permalink
convert @babel/helper-create-regexp-features-plugin to typescript (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbodya committed May 13, 2021
1 parent e21abad commit 72371cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
export const FEATURES = Object.freeze({
unicodeFlag: 1 << 0,
dotAllFlag: 1 << 1,
Expand All @@ -16,7 +15,7 @@ export const FEATURES = Object.freeze({
export const featuresKey = "@babel/plugin-regexp-features/featuresKey";
export const runtimeKey = "@babel/plugin-regexp-features/runtimeKey";

type FeatureType = $Values<typeof FEATURES>;
type FeatureType = typeof FEATURES[keyof typeof FEATURES];

export function enableFeature(features: number, feature: FeatureType): number {
return features | feature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function pullFlag(node, flag: RegExpFlags): void {
node.flags = node.flags.replace(flag, "");
}

declare const PACKAGE_JSON: { name: string; version: string };

// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
// as 70000100005. This method is easier than using a semver-parsing
// package, but it breaks if we release x.y.z where x, y or z are
Expand All @@ -33,7 +35,11 @@ const version = PACKAGE_JSON.version
.reduce((v, x) => v * 1e5 + +x, 0);
const versionKey = "@babel/plugin-regexp-features/version";

export function createRegExpFeaturePlugin({ name, feature, options = {} }) {
export function createRegExpFeaturePlugin({
name,
feature,
options = {} as any,
}) {
return {
name,
pre() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { FEATURES, hasFeature } from "./features";

export function generateRegexpuOptions(node, features) {
type RegexpuOptions = {
useUnicodeFlag: boolean;
onNamedGroup: (name: string, index: number) => void;
namedGroup: boolean;
unicodePropertyEscape: boolean;
dotAllFlag: boolean;
lookbehind: boolean;
};

export function generateRegexpuOptions(node, features): RegexpuOptions | null {
let useUnicodeFlag = false,
dotAllFlag = false,
unicodePropertyEscape = false,
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"./packages/babel-core/src/**/*.ts",
"./packages/babel-generator/src/**/*.ts",
"./packages/babel-helper-annotate-as-pure/src/**/*.ts",
"./packages/babel-helper-create-regexp-features-plugin/src/**/*.ts",
"./packages/babel-helper-explode-assignable-expression/src/**/*.ts",
"./packages/babel-helper-fixtures/src/**/*.ts",
"./packages/babel-helper-function-name/src/**/*.ts",
Expand Down Expand Up @@ -44,6 +45,9 @@
"@babel/helper-annotate-as-pure": [
"./packages/babel-helper-annotate-as-pure/src"
],
"@babel/helper-create-regexp-features-plugin": [
"./packages/babel-helper-create-regexp-features-plugin/src"
],
"@babel/helper-explode-assignable-expression": [
"./packages/babel-helper-explode-assignable-expression/src"
],
Expand Down

0 comments on commit 72371cb

Please sign in to comment.