diff --git a/test/function/named-external-method-in-prototype/_config.js b/test/function/named-external-method-in-prototype/_config.js new file mode 100644 index 0000000..249ad8f --- /dev/null +++ b/test/function/named-external-method-in-prototype/_config.js @@ -0,0 +1,15 @@ +module.exports = { + description: 'method of external named import used inside prototype method', + context: { + // override require here, making "foo" appear as a global module + require: function ( name ) { + if ( name === 'bar' ) { + return require( './bar' ); + } + return require( name ); + } + }, + options: { + external: [ 'bar' ] + }, +}; diff --git a/test/function/named-external-method-in-prototype/bar.js b/test/function/named-external-method-in-prototype/bar.js new file mode 100644 index 0000000..8ec450d --- /dev/null +++ b/test/function/named-external-method-in-prototype/bar.js @@ -0,0 +1,5 @@ +exports.bar = { + foobar: function () { + return 42; + } +}; diff --git a/test/function/named-external-method-in-prototype/foo.js b/test/function/named-external-method-in-prototype/foo.js new file mode 100644 index 0000000..9e4e7b5 --- /dev/null +++ b/test/function/named-external-method-in-prototype/foo.js @@ -0,0 +1,16 @@ +import { bar } from 'bar'; + +export default function Foo() { + // XXX: one does not even have to call the method, simply having it defined + // on the prototype triggers the failure + //return this.bar(); + return bar.foobar(); +} + +// XXX: this prototype definition throws it of, comment it out and it at least +// fails at runtime because it generates wrong code +Foo.prototype.bar = function () { + // XXX: it also has to be a nested function, simply calling `bar()` here + // works, or at least it fails ar runtime like the case above + return bar.foobar(); +}; diff --git a/test/function/named-external-method-in-prototype/main.js b/test/function/named-external-method-in-prototype/main.js new file mode 100644 index 0000000..fc0a49a --- /dev/null +++ b/test/function/named-external-method-in-prototype/main.js @@ -0,0 +1,5 @@ +// XXX: it has to be an imported module, otherwise it compiles and fails at +// runtime +import Foo from './foo.js'; + +assert.equal( new Foo(), 42 );