You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -53,14 +52,21 @@ It should have **binary retention** to be available from binary data.
53
52
54
53
Annotation **allowed on classes, properties and functions** according to what can be exported from JS modules.
55
54
55
+
_**Frontend:** prohibit to use the annotation on `var`_
56
+
<br/>
57
+
_It doesn't make sense on module systems except CommonJS (node.js)
58
+
and to use it with CommonJS we should call `require` on every call sites to get the current value._
59
+
<br/>
60
+
_Since it very rare case propose to prohibit it now._
61
+
56
62
In JS world objects often used as namespace/package so will be nice to allow to map such objects to Kotlin packages.
57
63
58
64
Why just not using objects in all cases?
59
65
1. Some IDE features works better with package level declarations (e.g. auto import)
60
66
2. Accessing to package must not have side effects, so in some cases we can generate better code (alternative solution is add marker annotation)
61
67
62
-
So to achieve that files allowed as target of the annotation.
63
-
But it's not enough, additionally we should provide the way to specify custom qualifier for native declarations in the file.
68
+
So to achieve that files allowed as the target of the annotation.
69
+
But it's not enough, additionally, we should provide the way to specify custom qualifier for native declarations in the file.
64
70
65
71
It can be achieved by adding yet another parameter to the annotation or add a new annotation, like:
66
72
@@ -72,9 +78,10 @@ annotation class JsPackage(val path: String)
72
78
[TODO] think up a better name.
73
79
74
80
The new annotation can be reused in case when we want to have package with long path in Kotlin,
75
-
but don't want to have long path in generated JS, e.g. for public API.
76
-
Of course, this problem can be fixed by adding another file "facade" with short qualifier.
81
+
but don't want to have a long path in generated JS, e.g. for public API.
82
+
Of course, this problem can be fixed by adding another file "facade" with a short qualifier.
77
83
84
+
// it can't part of JsModule becouse will be reused for native declarations inside nested namespaces/packages
78
85
79
86
Parameters:
80
87
-`import` -- string which will be used to import related module.
@@ -131,7 +138,7 @@ package MyExternalModule
131
138
@native funfoo() {}
132
139
```
133
140
134
-
**Export by assignment form toplevel**
141
+
**Export by assignment from toplevel**
135
142
136
143
In TypeScript:
137
144
```typescript
@@ -245,13 +252,14 @@ When **module kind is SIMPLE**
245
252
```
246
253
247
254
### Frontend
248
-
- Report error when try to use native declaration which has `JsModule` annotations, but no one specify rule for current module kind.
255
+
- Report error when try to use native declaration which has `JsModule` annotations, but no one specifies a rule for current module kind.
249
256
- Prohibit to have many annotations which explicitly provide the same module kind.
250
257
- Prohibit to apply `JsModule` annotation to non-native declarations, except files.<br/>
251
-
It can be relaxed later e.g. to reuse this annotation to allow translate a file to separate JS module, it can be useful to interop with some frameworks (see [KT-12093](https://youtrack.jetbrains.com/issue/KT-12093))
258
+
It can be relaxed later e.g. to reuse this annotation to allow translate a file to separate JS module,
259
+
it can be useful to interop with some frameworks (see [KT-12093](https://youtrack.jetbrains.com/issue/KT-12093))
252
260
253
261
### IDE
254
-
- Add inspection for case when some declarations with the same fq-name have different JsModule annotations?
262
+
- Add inspection for the case when some declarations with the same fq-
255
263
Consider next cases:
256
264
- function overloads
257
265
- package and functions
@@ -260,15 +268,15 @@ It can be relaxed later e.g. to reuse this annotation to allow translate a file
260
268
1. Can we introduce default value for `import` parameter of `JsModule` and use the name of declaration as import string when argument not provided?<br/>
261
269
If so, how it should work when the annotation used on file?
262
270
263
-
2. What should be default value of `kind` parameter of `JsModule`?
271
+
2. What should be used as default value of `kind` parameter of `JsModule`?
264
272
1. all kinds
265
273
2. all kinds except SIMPLE
266
274
267
275
In TypeScript (external) modules can be used only when compiler ran with module kind (in our terms it's all except SIMPLE).
268
-
So, should second be default to generate simpler code from TS declarations?
276
+
So, should the second be default to generate simpler code from TS declarations?
269
277
270
-
3. Actually right now we needs to know only is `kind === SIMPLE` or not, so should we simplify API?
278
+
3. Actually, right now we needs to know only is `kind === SIMPLE` or not, so should we simplify API?
271
279
272
-
4. Unfortunately we can't use constants for `kind` parameter to make API better. Can we fix it somehow?
280
+
4. Unfortunately, we can't use constants for `kind` parameter to make API better. Can we fix it somehow?
273
281
274
-
5. Will be nice to have the way to say that all declarations in this file is native. But how it fit with idea to replace `@native` with `external`?
282
+
5. Will be nice to have the way to say that all declarations in this file are native. But how it fit with the idea to replace `@native` with `external`?
0 commit comments