convert @babel/helper-create-regexp-features-plugin to typescript (#13215)
This commit is contained in:
parent
e21abad016
commit
72371cb637
@ -1,4 +1,3 @@
|
|||||||
// @flow
|
|
||||||
export const FEATURES = Object.freeze({
|
export const FEATURES = Object.freeze({
|
||||||
unicodeFlag: 1 << 0,
|
unicodeFlag: 1 << 0,
|
||||||
dotAllFlag: 1 << 1,
|
dotAllFlag: 1 << 1,
|
||||||
@ -16,7 +15,7 @@ export const FEATURES = Object.freeze({
|
|||||||
export const featuresKey = "@babel/plugin-regexp-features/featuresKey";
|
export const featuresKey = "@babel/plugin-regexp-features/featuresKey";
|
||||||
export const runtimeKey = "@babel/plugin-regexp-features/runtimeKey";
|
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 {
|
export function enableFeature(features: number, feature: FeatureType): number {
|
||||||
return features | feature;
|
return features | feature;
|
||||||
@ -24,6 +24,8 @@ function pullFlag(node, flag: RegExpFlags): void {
|
|||||||
node.flags = node.flags.replace(flag, "");
|
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
|
// 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
|
// 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
|
// package, but it breaks if we release x.y.z where x, y or z are
|
||||||
@ -33,7 +35,11 @@ const version = PACKAGE_JSON.version
|
|||||||
.reduce((v, x) => v * 1e5 + +x, 0);
|
.reduce((v, x) => v * 1e5 + +x, 0);
|
||||||
const versionKey = "@babel/plugin-regexp-features/version";
|
const versionKey = "@babel/plugin-regexp-features/version";
|
||||||
|
|
||||||
export function createRegExpFeaturePlugin({ name, feature, options = {} }) {
|
export function createRegExpFeaturePlugin({
|
||||||
|
name,
|
||||||
|
feature,
|
||||||
|
options = {} as any,
|
||||||
|
}) {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
pre() {
|
pre() {
|
||||||
@ -1,6 +1,15 @@
|
|||||||
import { FEATURES, hasFeature } from "./features";
|
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,
|
let useUnicodeFlag = false,
|
||||||
dotAllFlag = false,
|
dotAllFlag = false,
|
||||||
unicodePropertyEscape = false,
|
unicodePropertyEscape = false,
|
||||||
@ -6,6 +6,7 @@
|
|||||||
"./packages/babel-core/src/**/*.ts",
|
"./packages/babel-core/src/**/*.ts",
|
||||||
"./packages/babel-generator/src/**/*.ts",
|
"./packages/babel-generator/src/**/*.ts",
|
||||||
"./packages/babel-helper-annotate-as-pure/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-explode-assignable-expression/src/**/*.ts",
|
||||||
"./packages/babel-helper-fixtures/src/**/*.ts",
|
"./packages/babel-helper-fixtures/src/**/*.ts",
|
||||||
"./packages/babel-helper-function-name/src/**/*.ts",
|
"./packages/babel-helper-function-name/src/**/*.ts",
|
||||||
@ -44,6 +45,9 @@
|
|||||||
"@babel/helper-annotate-as-pure": [
|
"@babel/helper-annotate-as-pure": [
|
||||||
"./packages/babel-helper-annotate-as-pure/src"
|
"./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": [
|
"@babel/helper-explode-assignable-expression": [
|
||||||
"./packages/babel-helper-explode-assignable-expression/src"
|
"./packages/babel-helper-explode-assignable-expression/src"
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user