message: Only inject regenerator with ES5, and Babel helpers with <= ES2017.
diff: @@ -105,21 +105,14 @@ export class GenericOptimizeTransform extends Transform {
  }
  }
  -/**
  - * Transform JavaScript.
  - */
  -export class JsTransform extends GenericOptimizeTransform {
  - constructor(options: OptimizeOptions) {
  - const jsOptions: JsOptimizeOptions = options.js || {};
  -
  - function getCompileTarget(file: vinyl): JsCompileTarget|boolean {
  +function getCompileTarget(
  + file: vinyl, options: JsOptimizeOptions): JsCompileTarget|boolean {
  let target: JsCompileTarget|boolean|undefined;
  - const compileOptions = jsOptions.compile;
  - if (notExcluded(jsOptions.compile)(file)) {
  + const compileOptions = options.compile;
  + if (notExcluded(options.compile)(file)) {
  if (typeof compileOptions === 'object') {
  - target = (compileOptions.target === undefined) ?
  - true :
  - compileOptions.target;
  + target =
  + (compileOptions.target === undefined) ? true : compileOptions.target;
  } else {
  target = compileOptions;
  }
  @@ -132,6 +125,13 @@ export class JsTransform extends GenericOptimizeTransform {
  return target;
  }
  +/**
  + * Transform JavaScript.
  + */
  +export class JsTransform extends GenericOptimizeTransform {
  + constructor(options: OptimizeOptions) {
  + const jsOptions: JsOptimizeOptions = options.js || {};
  +
  const shouldMinifyFile =
  jsOptions.minify ? notExcluded(jsOptions.minify) : () => false;
  @@ -153,7 +153,7 @@ export class JsTransform extends GenericOptimizeTransform {
  }
  return jsTransform(content, {
  - compile: getCompileTarget(file),
  + compile: getCompileTarget(file, jsOptions),
  externalHelpers: true,
  minify: shouldMinifyFile(file),
  moduleResolution: jsOptions.moduleResolution,
  @@ -173,7 +173,7 @@ export class JsTransform extends GenericOptimizeTransform {
  */
  export class HtmlTransform extends GenericOptimizeTransform {
  constructor(options: OptimizeOptions) {
  - const anyJsCompiledToEs5 = options.js && !!options.js.compile;
  + const jsOptions: JsOptimizeOptions = options.js || {};
  const shouldMinifyFile = options.html && options.html.minify ?
  notExcluded(options.html.minify) :
  @@ -188,11 +188,27 @@ export class HtmlTransform extends GenericOptimizeTransform {
  let injectBabelHelpers: 'none'|'full'|'amd' = 'none';
  let injectRegeneratorRuntime = false;
  if (isEntryPoint) {
  - if (anyJsCompiledToEs5) {
  + const compileTarget = getCompileTarget(file, jsOptions);
  + switch (compileTarget) {
  + case 'es5':
  + case true:
  injectBabelHelpers = 'full';
  injectRegeneratorRuntime = true;
  - } else if (transformModulesToAmd) {
  - injectBabelHelpers = 'amd';
  + break;
  + case 'es2015':
  + case 'es2016':
  + case 'es2017':
  + injectBabelHelpers = 'full';
  + injectRegeneratorRuntime = false;
  + break;
  + case 'es2018':
  + case false:
  + injectBabelHelpers = transformModulesToAmd ? 'amd' : 'none';
  + injectRegeneratorRuntime = false;
  + break;
  + default:
  + const never: never = compileTarget;
  + throw new Error(`Unexpected compile target ${never}`);
  }
  }
  