I want to re-export the entire module and redefine only a specific re-export function. But it seems that the export of the override function is not processed when the same function is already re-exported.
( http://www.ecma-international.org/ecma-262/6.0/#sec-module-semantics-static-semantics-early-errors , 'This is a syntax error if ExportedNames of ModuleItemList contains any duplicate entries.')
The motivation for my approach is to minimize the explicit re-export of a very large or long module if I just want to redefine a specific function or method in a re-exported module.
Is there any way to implement my approach in es6 / es2015?
My code is:
module-a.js
export class MyFirstStandardClass { sendMeMessages() { return `hello, I'm a standard implementation`; } } export function talkToMe() { return `standard talking: how are you doing?`; }
module-b.js
import * as StandardModule from 'module-a'; export function talkToMe(condition = true) { if (condition) { return `project conditional talking: ${StandardModule.talkToMe()}`; } return `project without a condition!`; } export * from 'module-a';
module-c.js
import * as MyModule from 'module-b'; import React, { Component } from 'react'; export default class App extends Component { componentWillMount() { console.log(MyModule); this.myFirstStandardInstance = new MyModule.MyFirstStandardClass(); } render() { return ( <div> <label> Class </label> <div> { this.myFirstStandardInstance.sendMeMessages() } </div> <label> Function </label> <div> { MyModule.talkToMe(true) } // returns 'standard talking: how are you doing?'; expected 'project conditional talking: standard talking: how are you doing?' </div> </div> ); } }
source share