firefly-compiler 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/Release.ff +1 -0
- package/compiler/Parser.ff +1 -1
- package/core/JsSystem.ff +3 -0
- package/fireflysite/assets/markdown/reference/JavascriptInterop.md +26 -6
- package/output/js/ff/compiler/Parser.mjs +2 -2
- package/output/js/ff/core/JsSystem.mjs +8 -0
- package/package.json +1 -1
- package/vscode/package.json +1 -1
package/bin/Release.ff
CHANGED
|
@@ -39,6 +39,7 @@ release(
|
|
|
39
39
|
releaseFireflyPackage(system, accessKeyId, secretAccessKey, "webserver")
|
|
40
40
|
runSuccessful(system, "git", ["commit", "-a", "-m", "Autorelease " + version], system.path(".."))
|
|
41
41
|
runSuccessful(system, "git", ["push"], system.path(".."))
|
|
42
|
+
runSuccessful(system, "npm", ["install", "-g", "firefly-compiler"], system.path(".."))
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
releaseFireflyPackage(
|
package/compiler/Parser.ff
CHANGED
|
@@ -1201,7 +1201,7 @@ extend self: Parser {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
let target = DynamicCall(EField(token.at(), False, result, "with"), False)
|
|
1203
1203
|
result = ECall(record.at, target, effect, [], [
|
|
1204
|
-
Argument(argument.at, None, EString(argument.at, argument.name.grab()))
|
|
1204
|
+
Argument(argument.at, None, EString(argument.at, "\"" + argument.name.grab() + "\""))
|
|
1205
1205
|
Argument(argument.value.at, None, argument.value)
|
|
1206
1206
|
], [])
|
|
1207
1207
|
}
|
package/core/JsSystem.ff
CHANGED
|
@@ -12,17 +12,34 @@ Most JavaScript functionality can be accessed via the `JsSystem` object.
|
|
|
12
12
|
|
|
13
13
|
```firefly
|
|
14
14
|
browserMain(system: BrowserSystem): Unit {
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let js = system.js()
|
|
16
|
+
js->document->onclick = js->{
|
|
17
|
+
js->Notification->requestPermission()->then(js->{
|
|
18
|
+
js->Notification->(
|
|
19
|
+
"Hi!"
|
|
20
|
+
js->(body = "From the Firefly JS FFI")
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
```
|
|
20
26
|
|
|
21
|
-
This
|
|
27
|
+
This is equivalent to the following JavaScript:
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
```js
|
|
30
|
+
document.onclick = {() =>
|
|
31
|
+
Notification.requestPermission().then({() =>
|
|
32
|
+
new Notification(
|
|
33
|
+
"Hi!",
|
|
34
|
+
{body: "From the Firefly JS FFI"}
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `->` is shorthand for calling the methods `get`, `set`, `increment`, `decrement`, `object`, `call1`, `new1` and `function1` (substitute 0 to 9 for 1).
|
|
24
41
|
|
|
25
|
-
The
|
|
42
|
+
The `js` variable is of the type `JsSystem` and the rest of the expressions return `JsValue`, which represents an arbitrary JavaScript value.
|
|
26
43
|
|
|
27
44
|
|
|
28
45
|
# The ff:unsafejs package
|
|
@@ -44,6 +61,9 @@ throwIfCancelled(): Unit
|
|
|
44
61
|
|
|
45
62
|
// Returns true if the current task has been aborted
|
|
46
63
|
cancelled(): Bool
|
|
64
|
+
|
|
65
|
+
// Casts any Firefly value to a JavaScript value without conversion
|
|
66
|
+
value[T](value: T): JsValue
|
|
47
67
|
```
|
|
48
68
|
|
|
49
69
|
In the future, it may be possible to provide a whitelist of dependencies that are allowed to use this package.
|
|
@@ -1559,7 +1559,7 @@ if(ff_core_Option.Option_isEmpty(argument_.name_)) {
|
|
|
1559
1559
|
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(argument_.at_, "Expected a named argument"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
1560
1560
|
};
|
|
1561
1561
|
const target_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EField(ff_compiler_Token.Token_at(token_), false, result_, "with"), false);
|
|
1562
|
-
result_ = ff_compiler_Syntax.ECall(record_.at_, target_, effect_, [], [ff_compiler_Syntax.Argument(argument_.at_, ff_core_Option.None(), ff_compiler_Syntax.EString(argument_.at_, ff_core_Option.Option_grab(argument_.name_))), ff_compiler_Syntax.Argument(argument_.value_.at_, ff_core_Option.None(), argument_.value_)], [])
|
|
1562
|
+
result_ = ff_compiler_Syntax.ECall(record_.at_, target_, effect_, [], [ff_compiler_Syntax.Argument(argument_.at_, ff_core_Option.None(), ff_compiler_Syntax.EString(argument_.at_, (("\"" + ff_core_Option.Option_grab(argument_.name_)) + "\""))), ff_compiler_Syntax.Argument(argument_.value_.at_, ff_core_Option.None(), argument_.value_)], [])
|
|
1563
1563
|
}));
|
|
1564
1564
|
return result_
|
|
1565
1565
|
}
|
|
@@ -3169,7 +3169,7 @@ if(ff_core_Option.Option_isEmpty(argument_.name_)) {
|
|
|
3169
3169
|
throw Object.assign(new Error(), {ffException: ff_core_Any.toAny_(ff_compiler_Syntax.CompileError(argument_.at_, "Expected a named argument"), ff_compiler_Syntax.ff_core_Any_HasAnyTag$ff_compiler_Syntax_CompileError)})
|
|
3170
3170
|
};
|
|
3171
3171
|
const target_ = ff_compiler_Syntax.DynamicCall(ff_compiler_Syntax.EField(ff_compiler_Token.Token_at(token_), false, result_, "with"), false);
|
|
3172
|
-
result_ = ff_compiler_Syntax.ECall(record_.at_, target_, effect_, [], [ff_compiler_Syntax.Argument(argument_.at_, ff_core_Option.None(), ff_compiler_Syntax.EString(argument_.at_, ff_core_Option.Option_grab(argument_.name_))), ff_compiler_Syntax.Argument(argument_.value_.at_, ff_core_Option.None(), argument_.value_)], [])
|
|
3172
|
+
result_ = ff_compiler_Syntax.ECall(record_.at_, target_, effect_, [], [ff_compiler_Syntax.Argument(argument_.at_, ff_core_Option.None(), ff_compiler_Syntax.EString(argument_.at_, (("\"" + ff_core_Option.Option_grab(argument_.name_)) + "\""))), ff_compiler_Syntax.Argument(argument_.value_.at_, ff_core_Option.None(), argument_.value_)], [])
|
|
3173
3173
|
}));
|
|
3174
3174
|
return result_
|
|
3175
3175
|
}
|
|
@@ -179,6 +179,10 @@ export function JsSystem_object(self_) {
|
|
|
179
179
|
return {}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
export function JsSystem_new0(self_) {
|
|
183
|
+
return {}
|
|
184
|
+
}
|
|
185
|
+
|
|
182
186
|
export function JsSystem_array(self_, values_) {
|
|
183
187
|
return values_.slice()
|
|
184
188
|
}
|
|
@@ -307,6 +311,10 @@ export async function JsSystem_object$(self_, $task) {
|
|
|
307
311
|
throw new Error('Function JsSystem_object is missing on this target in async context.');
|
|
308
312
|
}
|
|
309
313
|
|
|
314
|
+
export async function JsSystem_new0$(self_, $task) {
|
|
315
|
+
throw new Error('Function JsSystem_new0 is missing on this target in async context.');
|
|
316
|
+
}
|
|
317
|
+
|
|
310
318
|
export async function JsSystem_array$(self_, values_, $task) {
|
|
311
319
|
throw new Error('Function JsSystem_array is missing on this target in async context.');
|
|
312
320
|
}
|
package/package.json
CHANGED