
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
71 lines
1.8 KiB
Plaintext
71 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Before ECMAScript 2015, module management had to be ad-hoc or provided by 3rd-party libraries such as Node.js, Webpack, or RequireJS. Fortunately, ES2015, provides language-standard mechanisms for module management, ``++import++`` and ``++export++``, and older usages should be converted.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
// circle.js
|
|
exports.area = function (r) {
|
|
return PI * r * r;
|
|
};
|
|
|
|
// foo.js
|
|
define(["./cart", "./horse"], function(cart, horse) { // Noncompliant
|
|
// ...
|
|
});
|
|
|
|
// bar.js
|
|
const circle = require('./circle.js'); // Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
// circle.js
|
|
let area = function (r) {
|
|
return PI * r * r;
|
|
}
|
|
export default area;
|
|
|
|
// foo.js
|
|
import cart from "./cart.js";
|
|
import horse from "./horse.js";
|
|
|
|
// bar.js
|
|
import circle from "./circle.js"
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use a standard "import" statement instead of "xxx".
|
|
|
|
|
|
=== Highlighting
|
|
|
|
``++define(...)++``, ``++require(...)++``
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 8 Feb 2016, 09:01:19 Elena Vilchik wrote:
|
|
\[~ann.campbell.2] WDYT about removing code examples at all?
|
|
|
|
=== on 8 Feb 2016, 09:44:14 Elena Vilchik wrote:
|
|
\[~ann.campbell.2] I don't like the following thing: for AMD (``++define++`` function) we will raise one issue per module (aka file). While for CommonJS (``++require++`` function) will raise one issue per imported module. I like second approach and suggest to raise one issue per imported module for AMD too (i.e. per element in first argument array). Then we can change the message to ``++Use a standard "import" statement to import module "XXX".++``.
|
|
|
|
endif::env-github,rspecator-view[]
|