Skip to content

bug ? addToken not work when XRegExp(pattern: RegExp) #240

@bluelovers

Description

@bluelovers

bug ? addToken not work when XRegExp(pattern: RegExp)

import addSupportToXRegExp, { IOptions } from 'xregexp-plugin-hanzi-cjk';
import * as XRegExp from 'xregexp';

let options: IOptions = {
	// set a flag if u only wanna trigger for this plugin, default is auto enable
	flags: '',
};

console.log(XRegExp.version);

// if didn't set xr, it is XRegExp
const xr1 = addSupportToXRegExp(null, options);
//const xr2 = addSupportToXRegExp(XRegExp, options);
//console.log('xr1 = xr2 = XRegExp', xr1 === xr2);

let r1 = '(の|像)';
let r2 = /(|)/;

// work when input is string
console.log(xr1(r1));
console.log(xr1(r1).test('象'));
console.log(xr1(r1).test('的'));

// fail when input is regexp
console.log(xr1(r2));
console.log(xr1(r2).test('象'));
console.log(xr1(r2).test('的'));
4.1.1
{ /([の之的]|[像象])/ xregexp: { captureNames: null, source: '(の|像)', flags: '' } }
true
true
{ /(の|像)/ xregexp: { captureNames: null, source: null, flags: null } }
false
false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions