Skip to content

Unexpected output with webpack2 #38

Closed
@hydra1983

Description

@hydra1983

The code below will assign the created RegExp to options.search, in webpack2, the options.search will be reused for next file processing. So, the RegExp will be another one other than the first one expected.

function processOptions(source, options) {
  if (!_.isUndefined(options.search) && !_.isUndefined(options.replace)) {
    if (!_.isUndefined(options.flags)) {
      options.search = new RegExp(options.search, options.flags);
    }

    var newSource = source.replace(options.search, options.replace);
    if (options.strict && (newSource === source)) {
      throw new Error('Cannot replace ' + options.search + '' + options.replace);
    }
  } else if (options.strict) {
    throw new Error('Cannot replace: undefined search or/and option(s) → ' + JSON.stringify(options));
  }

  return newSource;
}

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