-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for empty JS namespaces to represent top-level symbols
We currently don't have a way to overlay a native type that has form: ``` js goog.module('TopLevelClass'); exports = class {}; ``` With this change you'd now represent this as: ``` java @jstype(isNative = true, namespace = "", name = "TopLevelClass") class TopLevelClass {} ``` This all works since we currently treat the first component of the `name` attribute as the last component of the `goog.require` statement for `@JsType`. PiperOrigin-RevId: 599223849
- Loading branch information
1 parent
693ef13
commit 659e0bd
Showing
23 changed files
with
668 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/TopLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2024 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package nativejstypes; | ||
|
||
import jsinterop.annotations.JsType; | ||
|
||
@JsType(isNative = true, namespace = "", name = "toplevel") | ||
class TopLevel { | ||
private TopLevel() {} | ||
|
||
public static int x; | ||
|
||
@JsType(isNative = true) | ||
static class Nested { | ||
public int x; | ||
} | ||
} | ||
|
||
@JsType(isNative = true, namespace = "", name = "toplevel.Nested") | ||
class TopLevelNestedReference { | ||
public int x; | ||
} |
24 changes: 24 additions & 0 deletions
24
transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/native_sources/toplevel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
goog.module('toplevel'); | ||
|
||
exports.Nested = class Nested { | ||
constructor() { | ||
/** @type {number} */ | ||
this.x = 1; | ||
} | ||
}; | ||
|
||
/** @type {number} */ | ||
exports.x = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...google/j2cl/readable/java/nativejstypes/output_closure/TopLevel$$Overlay.impl.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
goog.module('nativejstypes.TopLevel.$Overlay$impl'); | ||
|
||
const $Util = goog.require('nativebootstrap.Util$impl'); | ||
const TopLevel = goog.require('toplevel'); | ||
|
||
/** @nodts */ | ||
class $Overlay { | ||
/** @nodts */ | ||
static $clinit() { | ||
$Overlay.$clinit = () =>{}; | ||
$Overlay.$loadModules(); | ||
} | ||
/** @nodts @return {boolean} */ | ||
static $isInstance(/** ? */ instance) { | ||
return instance instanceof TopLevel; | ||
} | ||
|
||
/** @nodts */ | ||
static $loadModules() {} | ||
} | ||
$Util.$setClassMetadata($Overlay, 'toplevel'); | ||
|
||
exports = $Overlay; | ||
|
||
//# sourceMappingURL=TopLevel$$Overlay.js.map |
8 changes: 8 additions & 0 deletions
8
.../com/google/j2cl/readable/java/nativejstypes/output_closure/TopLevel$$Overlay.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
goog.module('nativejstypes.TopLevel.$Overlay'); | ||
|
||
goog.require('nativebootstrap.Util'); | ||
goog.require('toplevel'); | ||
|
||
const $Overlay = goog.require('nativejstypes.TopLevel.$Overlay$impl'); | ||
/** @nodts */ | ||
exports = $Overlay; |
4 changes: 4 additions & 0 deletions
4
.../google/j2cl/readable/java/nativejstypes/output_closure/TopLevel$$Overlay.js.mappings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[TopLevel] => [$Overlay] | ||
[TopLevel] => [$clinit] | ||
[TopLevel] => [$Overlay.$clinit = () =>{};] "nativejstypes.TopLevel$$Overlay.<clinit>" | ||
[TopLevel] => [$Overlay.$loadModules();] "nativejstypes.TopLevel$$Overlay.<clinit>" |
25 changes: 25 additions & 0 deletions
25
...j2cl/readable/java/nativejstypes/output_closure/TopLevel$Nested$$Overlay.impl.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
goog.module('nativejstypes.TopLevel.Nested.$Overlay$impl'); | ||
|
||
const $Util = goog.require('nativebootstrap.Util$impl'); | ||
const TopLevel = goog.require('toplevel'); | ||
|
||
/** @nodts */ | ||
class $Overlay { | ||
/** @nodts */ | ||
static $clinit() { | ||
$Overlay.$clinit = () =>{}; | ||
$Overlay.$loadModules(); | ||
} | ||
/** @nodts @return {boolean} */ | ||
static $isInstance(/** ? */ instance) { | ||
return instance instanceof TopLevel.Nested; | ||
} | ||
|
||
/** @nodts */ | ||
static $loadModules() {} | ||
} | ||
$Util.$setClassMetadata($Overlay, 'toplevel.Nested'); | ||
|
||
exports = $Overlay; | ||
|
||
//# sourceMappingURL=TopLevel$Nested$$Overlay.js.map |
8 changes: 8 additions & 0 deletions
8
...ogle/j2cl/readable/java/nativejstypes/output_closure/TopLevel$Nested$$Overlay.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
goog.module('nativejstypes.TopLevel.Nested.$Overlay'); | ||
|
||
goog.require('nativebootstrap.Util'); | ||
goog.require('toplevel'); | ||
|
||
const $Overlay = goog.require('nativejstypes.TopLevel.Nested.$Overlay$impl'); | ||
/** @nodts */ | ||
exports = $Overlay; |
4 changes: 4 additions & 0 deletions
4
.../j2cl/readable/java/nativejstypes/output_closure/TopLevel$Nested$$Overlay.js.mappings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Nested] => [$Overlay] | ||
[Nested] => [$clinit] | ||
[Nested] => [$Overlay.$clinit = () =>{};] "nativejstypes.TopLevel$Nested$$Overlay.<clinit>" | ||
[Nested] => [$Overlay.$loadModules();] "nativejstypes.TopLevel$Nested$$Overlay.<clinit>" |
25 changes: 25 additions & 0 deletions
25
...dable/java/nativejstypes/output_closure/TopLevelNestedReference$$Overlay.impl.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
goog.module('nativejstypes.TopLevelNestedReference.$Overlay$impl'); | ||
|
||
const $Util = goog.require('nativebootstrap.Util$impl'); | ||
const toplevel = goog.require('toplevel'); | ||
|
||
/** @nodts */ | ||
class $Overlay { | ||
/** @nodts */ | ||
static $clinit() { | ||
$Overlay.$clinit = () =>{}; | ||
$Overlay.$loadModules(); | ||
} | ||
/** @nodts @return {boolean} */ | ||
static $isInstance(/** ? */ instance) { | ||
return instance instanceof toplevel.Nested; | ||
} | ||
|
||
/** @nodts */ | ||
static $loadModules() {} | ||
} | ||
$Util.$setClassMetadata($Overlay, 'toplevel.Nested'); | ||
|
||
exports = $Overlay; | ||
|
||
//# sourceMappingURL=TopLevelNestedReference$$Overlay.js.map |
8 changes: 8 additions & 0 deletions
8
...l/readable/java/nativejstypes/output_closure/TopLevelNestedReference$$Overlay.java.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
goog.module('nativejstypes.TopLevelNestedReference.$Overlay'); | ||
|
||
goog.require('nativebootstrap.Util'); | ||
goog.require('toplevel'); | ||
|
||
const $Overlay = goog.require('nativejstypes.TopLevelNestedReference.$Overlay$impl'); | ||
/** @nodts */ | ||
exports = $Overlay; |
4 changes: 4 additions & 0 deletions
4
...adable/java/nativejstypes/output_closure/TopLevelNestedReference$$Overlay.js.mappings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[TopLevelNestedReference] => [$Overlay] | ||
[TopLevelNestedReference] => [$clinit] | ||
[TopLevelNestedReference] => [$Overlay.$clinit = () =>{};] "nativejstypes.TopLevelNestedReference$$Overlay.<clinit>" | ||
[TopLevelNestedReference] => [$Overlay.$loadModules();] "nativejstypes.TopLevelNestedReference$$Overlay.<clinit>" |
24 changes: 24 additions & 0 deletions
24
...output_closure/com/google/j2cl/readable/java/nativejstypes/native_sources/toplevel.js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
goog.module('toplevel'); | ||
|
||
exports.Nested = class Nested { | ||
constructor() { | ||
/** @type {number} */ | ||
this.x = 1; | ||
} | ||
} | ||
|
||
/** @type {number} */ | ||
exports.x = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
transpiler/javatests/com/google/j2cl/readable/java/nativejstypes/output_kt/TopLevel.kt.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Generated from "nativejstypes/TopLevel.java" | ||
@file:Suppress( | ||
"ALWAYS_NULL", | ||
"PARAMETER_NAME_CHANGED_ON_OVERRIDE", | ||
"REPEATED_BOUND", | ||
"SENSELESS_COMPARISON", | ||
"UNCHECKED_CAST", | ||
"UNNECESSARY_LATEINIT", | ||
"UNNECESSARY_NOT_NULL_ASSERTION", | ||
"UNREACHABLE_CODE", | ||
"UNUSED_ANONYMOUS_PARAMETER", | ||
"UNUSED_PARAMETER", | ||
"UNUSED_VARIABLE", | ||
"USELESS_CAST", | ||
"VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL", | ||
"VARIABLE_WITH_REDUNDANT_INITIALIZER") | ||
|
||
package nativejstypes | ||
|
||
import javaemul.lang.* | ||
import jsinterop.annotations.JsType | ||
import kotlin.Int | ||
import kotlin.Suppress | ||
import kotlin.jvm.JvmField | ||
|
||
@JsType(name = "toplevel", namespace = "", isNative = true) | ||
open class TopLevel { | ||
internal constructor() | ||
|
||
companion object { | ||
@JvmField | ||
var x: Int = 0 | ||
} | ||
|
||
@JsType(isNative = true) | ||
open class Nested internal constructor() { | ||
@JvmField | ||
var x: Int = 0 | ||
} | ||
} | ||
|
||
@JsType(name = "toplevel.Nested", namespace = "", isNative = true) | ||
open class TopLevelNestedReference internal constructor() { | ||
@JvmField | ||
var x: Int = 0 | ||
} |
Oops, something went wrong.