Commit Graph
18 Commits
Author SHA1 Message Date
Sébastien Theys cc9e2c147c [REF] web, mail, *: tests: remove legacy file utils
* = mrp

closes odoo/odoo#136141

Related: odoo/enterprise#47716
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2023-09-22 11:55:58 +00:00
Michael (mcm) 517d3258f2 [REF] web,*: add dependencies param to odoo.define
This commit makes the `dependencies` param of
`odoo.define` mandatory. It was optional and when
omitted, a regexp read the function to find the
dependencies. We can simplify it now almost all js
modules have been converted to esm.
The transpiler already adds the param for the es
modules except if the module has an alias.

task id: 3271352

closes odoo/odoo#119145

Related: odoo/enterprise#40040
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
2023-05-03 12:39:30 +02:00
Michael (mcm) 1e1c447d0d [REF] tools: transpile esm to sync module
This commit changes the js transpiler to write sync module.
The goal is to remove all async module and simplify the
module loader in the future.

task id: 3265979

closes odoo/odoo#119186

Signed-off-by: Géry Debongnie <ged@odoo.com>
2023-04-21 23:46:16 +02:00
Alexandre Kühn 7139ae416e [IMP] tools: put QUnit.only test in module wrap
Before this commit, when filtering tests by odoo module,
tests registered with `QUnit.test` and `QUnit.debug` were
listed, but not `QUnit.only`.

closes odoo/odoo#108591

Signed-off-by: Géry Debongnie <ged@odoo.com>
2022-12-23 15:08:18 +01:00
Olivier Dony 9bd642de7f [FIX] tools/transpiler: avoid nested quantifiers
It made the regex much slower in case of non-match, due to backtracking.

closes odoo/odoo#108046

X-original-commit: 56b1b17d6fdf493368ce219f981f94d9efdc9b7f
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
2022-12-21 11:26:32 +01:00
FrancoisGe 8e3de77042 [IMP] tools: adds the dependencies in the odoo.define
After this commit, the transpiler will add the dependencies of a file
to the second argument of the odoo.define(...).

For example:
odoo.define("@test/test", ['@test/dep1', '@test/dep2'], async function (require)

With this change, the code for the module system in the browser will get
directly the dependencies instead of having to stringify the function
defining a module, and grep inside for the "require" words.

closes odoo/odoo#105651

Taskid: 3062390
Related: odoo/enterprise#34895
Signed-off-by: Géry Debongnie <ged@odoo.com>
2022-12-15 16:47:05 +01:00
FrancoisGe b1f87e1088 [IMP] tools: transpiler adds a QUnit.module to js test files
The purpose of this improvement is to easily identify the module of a
test and to be able to run only the tests of a module.

closes odoo/odoo#105530

Task-id: 3062058
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2022-11-21 11:50:05 +01:00
Samuel Degueldre 69486d5260 [FIX] tools, test_assetsbundle: support trailing comma in named imports
Previously, when importing both the default export and named imports
with a trailing comma, we would transpile into an object where the first
keys were the named imports, including any trailing comma, and
concatenating with the default import with a leading comma, this means
that the trailing comma would transpile to two successive commas which
is not valid syntax.

This commit fixes that by putting the default import first, and adding
the named imports after, preserving the trailing comma if any, but
precluding the possibility that we get two commas back to back.

closes odoo/odoo#93693

X-original-commit: 798d2f2c6e8a496f4ce0cd3c4f1609693e692254
Signed-off-by: Géry Debongnie <ged@odoo.com>
Signed-off-by: Samuel Degueldre <sad@odoo.com>
2022-06-16 11:25:11 +02:00
Samuel Degueldre 284ce4b7a4 [IMP] tools, test_js_transpiler: add support for import default + named
Previously, importing the default export on the same line as the named
exports was not supported, this commit adds support for that in order to
allow removing duplicate imports.

before:
import something from "path";
import { A } from "path";

after:
import something, { A } from "path";

Part-of: odoo/odoo#84530
2022-02-15 09:26:53 +00:00
Xavier Morel bdc9d9d369 [FIX] core; base: lots of docstrings
* add configuration for `flake8[flake8-rst-docstring]`
* enable docstring-related checks
* fix invalid docstrings in odoo's core & `base`
* fix a few more bits (mostly missing or incorrect `:param:` info
  fields) are out of scope for the lint but my editor catches

closes odoo/odoo#74604

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2021-12-09 14:36:58 +00:00
FrancoisGe 13d0741a47 [FIX] js_transpiler: exported hoisting function
After this commit, the js_transpiler will support exported hoisting
function. So it will be possible to define a hoisting function and
exported in an @odoo-module.

Example of exported hoisting function which wasn't supported before
this commit:
```
  hoisted();
  export function hoisted() {
    ...
  };
```

closes odoo/odoo#80965

X-original-commit: 40ef9f7aeac8048cce8f002c84181abc64bcbe87
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-12-07 14:41:46 +00:00
Louis Wicket (wil) 39cb65f79a [IMP] core: enable top level await in odoo modules
Transpile odoo-modules into async function rather than simple functions.
The aim of this change is to support top-level await.

closes odoo/odoo#74629

Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
2021-08-03 13:12:37 +00:00
Nicolas Bayet 4600086e7a [IMP] web_editor: move odoo-editor into odoo
The code of the Odoo editor was on another repository
and that created unnecessary overhead. This commit move
the code inside Odoo and slightly change the folder
structure.

Related PR:
saas-14.3: #73345
saas-14.4: #73348

closes odoo/odoo#73272

Master: #73272
Signed-off-by: Antoine Guenet <Zinston@users.noreply.github.com>
2021-07-08 15:31:45 +00:00
Francois (fge) 27da86a138 [FIX] base: Catastrophic Backtracking in js_transpiler
This commit is to fix two problems when transpiling an @odoo-module file.

1. When a file exports an object with a long name, the regex EXPORT_FROM_RE will cause catastrophic backtracking. The regex will take a long time to resolve.
Example:
```js
    export {a, aReallyVeryLongNameElement};
```

2.  When a file exports an object without ending the line with ';'. The regex EXPORT_OBJECT_RE will remove spaces and line breaks that follow this kind of export.
Example:
Input:
```js
    export {a}

    xxx
```

Output:
```js
    Object.assign(__export, {a})xxx
```

Output after this commit:
```js
    Object.assign(__export, {a})

    xxx
```

closes odoo/odoo#68868

Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2021-04-15 13:40:02 +00:00
Francois (fge) 9c804aace3 [FIX] base: js_transpiler import legacy module
In a @odoo-module js file, importing a legacy module that did not have
a name respecting the "addon.name" format was not supported.

This commit will support all keys that do not start with a "." or "@".
This commit will also improve some regexes allowing to extract path.

Legacy module name supported:
    import X from "some/path"
    import X from "addon.name"

Legacy module name not supported:
(relative path and @module/path are only used to import @odoo-module js
files)
    import X from "@some/path"
    import X from "./some/path"
    import X from "../../some/path"

closes odoo/odoo#68152

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
2021-03-23 14:15:02 +00:00
Francois (fge) 7b53bb4b6f [FIX] base: @odoo-module alias ending with **/
When you define an @odoo-module with an alias without any space between
the alias and the **/, the alias contains the **/.
The purpose of this commit is to no longer add the **/ to the alias.

Example:
/** @odoo-module alias=web.base**/

Before:
  odoo.define(`web.base**/`, function(require) {
After:
  odoo.define(`web.base`, function(require) {

closes odoo/odoo#66929

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-02-26 16:06:43 +00:00
Simon Genin (ges) 551b4902f2 [FIX] tools: issue with module detection/special characters in JS transpiler
This commit fixes two unrelated small issues in the JS transpiler regexps:
- handle special chars in file url (so, one can now use a "-" in a file url)
- issue with the @odoo-module detection: it required 2 spaces after the @odoo-module word, because of the way the regexp was constructed. It also required spaces at the start of the line. All those have been fixed.

closes odoo/odoo#66255

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
2021-02-16 16:24:18 +00:00
Simon Genin (ges)andFrancois 929fec3a54 [IMP] base: add support for native JS modules
Because of the way Odoo works at its core, we do not know before hand
which files will be loaded as an asset in the browser, because it
depends on the installed Odoo addons.  This is why it is historically
difficult to integrate Odoo with standard JS tooling, and this is why
Odoo needs to use a custom javascript module system.

However, there is a way to use native JS modules (and gain all the
benefits from it: IDE autocompletion, ease of refactoring, intellisense,
...): we can write JS as native JS modules, but convert them at runtime
into Odoo custom modules. This is exactly the strategy applied by this
PR.

This has a lot of benefits, but there is a downside: we can no longer
serve statically JS files in debug=assets.  This would be a dealbreaker,
if we did not have sourcemaps (implemented in the next commit).

This commit introduces the python code that will transpile native JS
modules into odoo JS modules.

Task ID: 2414902
PR: 63177

Co-authored-by: Francois (fge) <fge@odoo.com>
2021-02-15 10:18:11 +01:00