File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed
Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,9 @@ export default class File {
203203 if ( res ) return res ;
204204 }
205205
206+ // make sure that the helper exists
207+ helpers . ensure ( name ) ;
208+
206209 const uid = ( this . declarations [ name ] = this . scope . generateUidIdentifier (
207210 name ,
208211 ) ) ;
Original file line number Diff line number Diff line change @@ -788,4 +788,28 @@ describe("api", function() {
788788 ) ;
789789 } ) ;
790790 } ) ;
791+
792+ describe ( "missing helpers" , function ( ) {
793+ it ( "should always throw" , function ( ) {
794+ expect ( ( ) =>
795+ babel . transformSync ( `` , {
796+ configFile : false ,
797+ plugins : [
798+ function ( ) {
799+ return {
800+ visitor : {
801+ Program ( path ) {
802+ try {
803+ path . pushContainer ( "body" , this . addHelper ( "fooBar" ) ) ;
804+ } catch { }
805+ path . pushContainer ( "body" , this . addHelper ( "fooBar" ) ) ;
806+ } ,
807+ } ,
808+ } ;
809+ } ,
810+ ] ,
811+ } ) ,
812+ ) . toThrow ( ) ;
813+ } ) ;
814+ } ) ;
791815} ) ;
Original file line number Diff line number Diff line change @@ -280,6 +280,10 @@ export function getDependencies(name: string): $ReadOnlyArray<string> {
280280 return Array . from ( loadHelper ( name ) . dependencies . values ( ) ) ;
281281}
282282
283+ export function ensure(name: string) {
284+ loadHelper ( name ) ;
285+ }
286+
283287export const list = Object.keys(helpers)
284288 .map(name => name . replace ( / ^ _ / , "" ) )
285289 . filter ( name => name !== "__esModule" ) ;
You can’t perform that action at this time.
0 commit comments