Skip to content

Commit 5936cda

Browse files
authored
Merge pull request #3945 from NoelDeMartin/MOBILE-4527
MOBILE-4527 compile: Fix JIT modules
2 parents 0cff22c + afb5ce3 commit 5936cda

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

local_moodleappbehat/classes/output/mobile.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ class mobile {
2727
* @return array View data.
2828
*/
2929
public static function view_index() {
30+
global $OUTPUT;
31+
3032
$templates = [
3133
[
3234
'id' => 'main',
33-
'html' => '<h1 class="text-center">Hello<span id="username"></span>!</h1>',
35+
'html' => $OUTPUT->render_from_template('local_moodleappbehat/mobile', []),
3436
],
3537
];
3638

39+
$otherdata = ['answer' => null];
3740
$javascript = file_get_contents(__DIR__ . '/../../js/mobile/index.js');
3841

39-
return compact('templates', 'javascript');
42+
return compact('templates', 'otherdata', 'javascript');
4043
}
4144

4245
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{=<% %>=}}
2+
<h1 class="text-center">Hello<span id="username"></span>!</h1>
3+
4+
<ion-list>
5+
<ion-item>
6+
<ion-label position="floating">What is the answer to the Ultimate Question of Life, The Universe, and Everything?</ion-label>
7+
<ion-input [(ngModel)]="CONTENT_OTHERDATA.answer"></ion-input>
8+
</ion-item>
9+
<ion-item *ngIf="CONTENT_OTHERDATA.answer === '42'">
10+
<ion-label>That is correct!</ion-label>
11+
</ion-item>
12+
<ion-item *ngIf="CONTENT_OTHERDATA.answer && CONTENT_OTHERDATA.answer !== '42'">
13+
<ion-label>That is not correct!</ion-label>
14+
</ion-item>
15+
</ion-list>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff --git a/node_modules/@angular/compiler/fesm2022/compiler.mjs b/node_modules/@angular/compiler/fesm2022/compiler.mjs
2+
index 5831cd3..c0ae072 100755
3+
--- a/node_modules/@angular/compiler/fesm2022/compiler.mjs
4+
+++ b/node_modules/@angular/compiler/fesm2022/compiler.mjs
5+
@@ -6072,13 +6072,41 @@ var R3NgModuleMetadataKind;
6+
R3NgModuleMetadataKind[R3NgModuleMetadataKind["Global"] = 0] = "Global";
7+
R3NgModuleMetadataKind[R3NgModuleMetadataKind["Local"] = 1] = "Local";
8+
})(R3NgModuleMetadataKind || (R3NgModuleMetadataKind = {}));
9+
+
10+
+/**
11+
+ * These are the only modules we're using to compile dynamic templates, we don't need to force JIT anywhere else.
12+
+ *
13+
+ * In particular, they are imported like this:
14+
+ * - CommonModule
15+
+ * - FormsModule -> ɵInternalFormsSharedModule -> RadioControlRegistryModule
16+
+ * - IonicModule -> CommonModule
17+
+ * - ReactiveFormsModule -> ɵInternalFormsSharedModule -> RadioControlRegistryModule
18+
+ * - TranslateModule
19+
+ */
20+
+const jitModules = [
21+
+ 'CommonModule',
22+
+ 'FormsModule',
23+
+ 'IonicModule',
24+
+ 'ɵInternalFormsSharedModule',
25+
+ 'RadioControlRegistryModule',
26+
+ 'ReactiveFormsModule',
27+
+ 'TranslateModule',
28+
+];
29+
+
30+
/**
31+
* Construct an `R3NgModuleDef` for the given `R3NgModuleMetadata`.
32+
*/
33+
function compileNgModule(meta) {
34+
const statements = [];
35+
const definitionMap = new DefinitionMap();
36+
+ const moduleName = meta.type.value?.node.loc?.identifierName;
37+
definitionMap.set('type', meta.type.value);
38+
+
39+
+ if (moduleName && jitModules.includes(moduleName)) {
40+
+ // Force JIT compilation.
41+
+ meta.selectorScopeMode = R3SelectorScopeMode.Inline;
42+
+ }
43+
+
44+
// Assign bootstrap definition. In local compilation mode (i.e., for
45+
// `R3NgModuleMetadataKind.LOCAL`) we assign the bootstrap field using the runtime
46+
// `ɵɵsetNgModuleScope`.

src/core/features/siteplugins/tests/behat/plugins.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ Feature: Plugins work properly.
1919
When I press the more menu button in the app
2020
And I press "Moodle App Behat (auto-generated)" in the app
2121
Then I should find "Lifecycle hook called" in the app
22+
23+
Scenario: Use Angular directives
24+
Given I entered the app as "studentusername"
25+
When I press the more menu button in the app
26+
And I press "Moodle App Behat (auto-generated)" in the app
27+
And I set the field "the Ultimate Question" to "42" in the app
28+
Then I should find "That is correct!" in the app

0 commit comments

Comments
 (0)