es6-modules

how to make script loading and es6 module loading working together?

喜你入骨 提交于 2019-12-12 14:21:33
问题 This loads jquery only once: <script type="module"> import "./js/jquery.js"; import "./js/jquery.js"; </script> The same is true for: <script type="module"> import "./js/jquery.js"; </script> <script type="module"> import "./js/jquery.js"; </script> But this loads jquery two times : <script src="./js/jquery.js"></script> <script type="module"> import "./js/jquery.js"; </script> Is it possible somehow to tell the browser's ES6 modules resolver that after first <script src="./js/jquery.js"><

How to spy on an imported function using Sinon?

≡放荡痞女 提交于 2019-12-12 13:34:14
问题 Let's say we want to test that a specific function is called by another function using Sinon. fancyModule.js export const fancyFunc = () => { console.log('fancyFunc') } export default const fancyDefault = () => { console.log('fancyDefault') fancyFunc() } fancyModule.test.js import sinon from 'sinon' import fancyDefault, { fancyFunc } from '../fancyModule' describe('fancyModule', () => { it('calls fancyFunc', () => { const spy = sinon.spy(fancyFunc) fancyDefault() expect(spy.called).to.be.true

Import ES6 module elements directly or destructure const assignment following the import? [closed]

回眸只為那壹抹淺笑 提交于 2019-12-12 10:04:18
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Somewhat new to ES6 modules and find myself torn between the following 2 patterns... Pattern #1 - Destructuring on import import { func1, func2, func3 } from 'my-funcs'; Pattern #2 - Destructuring on const import * as myFuncs from 'my-funcs'; const { func1, func2, func3 } =

How do you build, bundle & minify ES6-modules?

和自甴很熟 提交于 2019-12-12 09:41:20
问题 Due the fact, that ES6-modules (JavaScript-modules) are available for testing: https://www.chromestatus.com/feature/5365692190687232 https://medium.com/dev-channel/es6-modules-in-chrome-canary-m60-ba588dfb8ab7 I wonder, how should I minify and prepare the project release-file? Earlier, I havde bundled all JavaScript-files into the single and minified file, except situations, where I have to load the JS-file dynamically via XHR or Fetch API. As I understand, it's rather impossible to prepare a

ES6: Super class doesn't hold state

假如想象 提交于 2019-12-12 05:31:57
问题 I'm trying to figure out what's going on here, as the Parent/Super class does not have data after the initial construction. // imports/server/a-and-b.js class A { constructor(id) { // make MongoDB call and store inside this variable // ... this._LocalVariable = FieldFromMongo; console.log(`this._LocalVariable: ${this._LocalVariable}`); // => This has a good value, ie: 'Test' } get LocalVar() { console.log(`this._LocalVariable: ${this._LocalVariable}`); // => This has a undefined value when

Can ES6 constructors be stubbed more easily with Sinon?

丶灬走出姿态 提交于 2019-12-11 18:37:15
问题 Given the (overly simplified) snippet: import Validator from 'validator'; export default function isValid(arg) { // Validator#isValid is an ES6 getter return new Validator(arg).isValid; } How can I test that a Validator was instantiated with the given parameter? And stub isValid ? I know I can restructure my code to avoid the issue, I am not looking for a workaround as I found plenty (dependency injection, not using ES6 sugar, etc.). I found a way, but it is terribly ugly. In test file:

JavaScript: How could we import ES6 modules which are interdependent?

ε祈祈猫儿з 提交于 2019-12-11 17:24:20
问题 Hello and thank you for your time, I am beginner learning JavaScript and I would like to know how is this difficulty faced: We would like to import module A which is a npm module and has ES6 export syntax: import * as A from 'a'; Then, we would like to use another file which has also ES6 export and depends on the first one, so it would be used as: A.B import B from 'b'; Why does the console output the following? B.js Reference Error: A is not defined If you are curious, this is a

Can I export default from a variable?

帅比萌擦擦* 提交于 2019-12-11 16:42:31
问题 I would like to change my export { default } from 'MyFile' depending on certain conditions, so can I replace the file with a string variable? Currently I have something like this: let exportFrom if(SOME_CONDITION) { exportFrom = '../Something/Blah' } else { exportFrom = './SomethingElse' } export { default } from exportFrom This currently doesn't work as I get: Parsing error: Unexpected token Is there a way to do this? It is also important to note, that the reason I am doing this in the first

No exported symbols with es6 modules library compiled by Closure Compiler

不想你离开。 提交于 2019-12-11 07:00:48
问题 Starting point : Many js files are successfully compiled (no warning/error) by Closure Compiler (ADVANCED_OPTIMIZATIONS level) in a single library file. In these js files: goog.require and goog.provide are used to import/export things between them /** @export */ is used in front of whatever (const/function/Class/var) is required outside the library. Some HTML files include the library and some non compiled js accessing successfully to all whatever defined in this library. What I want: move to

Dependencies solving for GridComponent in @syncfusion/ej2-ng-grids

£可爱£侵袭症+ 提交于 2019-12-11 06:25:19
问题 I followed this tutorial http://ej2.syncfusion.com/angular/documentation/grid/getting-started.html How ever when I run my project, the JIT encounter this error The InteliSense also show the same error I set up the SyncFusionModule as Angular Module to export all "Syncfusion EJ 2 for Angular" components I'm planning to use in the BenchmarkModule . The GridComponent in @syncfusion/ej2-ng-grids/src/grid/index can be picked up by Angular; therefore, it is recognized as an Angular component.