File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ import deepClone from "lodash/cloneDeep";
22import sourceMapSupport from "source-map-support" ;
33import * as registerCache from "./cache" ;
44import escapeRegExp from "lodash/escapeRegExp" ;
5- import * as babel from "@babel/core" ;
5+ import * as babelCore from "@babel/core" ;
66import { OptionManager , DEFAULT_EXTENSIONS } from "@babel/core" ;
77import { addHook } from "pirates" ;
88import fs from "fs" ;
99import path from "path" ;
1010
1111const maps = { } ;
1212const transformOpts = { } ;
13+ let babel = babelCore ;
1314let piratesRevert = null ;
1415
1516function installSourceMapSupport ( ) {
@@ -100,6 +101,9 @@ register({
100101export default function register ( opts ?: Object = { } ) {
101102 // Clone to avoid mutating the arguments object with the 'delete's below.
102103 opts = Object . assign ( { } , opts ) ;
104+
105+ if ( opts . babel ) babel = opts . babel ;
106+
103107 if ( opts . extensions ) hookExtensions ( opts . extensions ) ;
104108
105109 if ( opts . cache === false && cache ) {
@@ -110,6 +114,7 @@ export default function register(opts?: Object = {}) {
110114 cache = registerCache . get ( ) ;
111115 }
112116
117+ delete opts . babel ;
113118 delete opts . extensions ;
114119 delete opts . cache ;
115120
Original file line number Diff line number Diff line change @@ -103,4 +103,20 @@ describe("@babel/register", function() {
103103 chai . expect ( ( gen_error = require ( GEN_ERROR ) ) ) . to . be . ok ;
104104 chai . expect ( gen_error ( ) ) . to . match ( / g e n _ e r r o r \. j s : 2 : 8 6 / ) ;
105105 } ) ;
106+
107+ it ( "uses custom babel when requested" , ( ) => {
108+ setupRegister ( {
109+ babel : {
110+ transform ( ) {
111+ return { code : "module.exports = 'hello';" } ;
112+ } ,
113+ getEnv ( ) {
114+ return { } ;
115+ } ,
116+ version : "custom" ,
117+ } ,
118+ } ) ;
119+
120+ chai . expect ( require ( DATA_ES2015 ) ) . to . equal ( "hello" ) ;
121+ } ) ;
106122} ) ;
You can’t perform that action at this time.
0 commit comments