Sha256: 138b84f2313d5030afc7e4ef54d92fb686ee1b442895c55e024a7cf1c5eab72b

Contents?: true

Size: 1.32 KB

Versions: 10

Compression:

Stored size: 1.32 KB

Contents

/**
 * The MIT License (MIT)
 * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
 */

'use strict';

/**
 * A regexp-tree plugin to translate `/./s` to `/[\0-\uFFFF]/`.
 */

module.exports = {

  // Whether `u` flag present. In which case we transform to
  // \u{10FFFF} instead of \uFFFF.
  _hasUFlag: false,

  // Only run this plugin if we have `s` flag.
  shouldRun: function shouldRun(ast) {
    var shouldRun = ast.flags.includes('s');

    if (!shouldRun) {
      return false;
    }

    // Strip the `s` flag.
    ast.flags = ast.flags.replace('s', '');

    // Whether we have also `u`.
    this._hasUFlag = ast.flags.includes('u');

    return true;
  },
  Char: function Char(path) {
    var node = path.node;


    if (node.kind !== 'meta' || node.value !== '.') {
      return;
    }

    var toValue = '\\uFFFF';
    var toSymbol = '\uFFFF';

    if (this._hasUFlag) {
      toValue = '\\u{10FFFF}';
      toSymbol = '\uDBFF\uDFFF';
    }

    path.replace({
      type: 'CharacterClass',
      expressions: [{
        type: 'ClassRange',
        from: {
          type: 'Char',
          value: '\\0',
          kind: 'decimal',
          symbol: '\0'
        },
        to: {
          type: 'Char',
          value: toValue,
          kind: 'unicode',
          symbol: toSymbol
        }
      }]
    });
  }
};

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
condenser-0.0.8 lib/condenser/processors/node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
jester-data-8.0.0 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-5.2.1 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-2.0.1 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-1.1.0 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-1.0.0 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
condenser-0.0.7 lib/condenser/processors/node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-0.0.0.1.0 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
ezii-os-0.0.0.0.1 node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js
condenser-0.0.5 lib/condenser/processors/node_modules/regexp-tree/dist/compat-transpiler/transforms/compat-dotall-s-transform.js