-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement first class mixins (#2073)
Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
- Loading branch information
1 parent
310904e
commit ce545c2
Showing
20 changed files
with
396 additions
and
91 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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2019 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
/// A registry of some `T` indexed by ID so that the host can invoke | ||
/// them. | ||
final class OpaqueRegistry<T> { | ||
/// Instantiations of `T` that have been sent to the host. | ||
/// | ||
/// The values are located at indexes in the list matching their IDs. | ||
final _elementsById = <T>[]; | ||
|
||
/// A reverse map from elements to their indexes in [_elementsById]. | ||
final _idsByElement = <T, int>{}; | ||
|
||
/// Returns the compiler-side id associated with [element]. | ||
int getId(T element) { | ||
var id = _idsByElement.putIfAbsent(element, () { | ||
_elementsById.add(element); | ||
return _elementsById.length - 1; | ||
}); | ||
|
||
return id; | ||
} | ||
|
||
/// Returns the compiler-side element associated with [id]. | ||
/// | ||
/// If no such element exists, returns `null`. | ||
T? operator [](int id) => _elementsById[id]; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2021 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:node_interop/js.dart'; | ||
|
||
import '../../callable.dart'; | ||
import '../../value.dart'; | ||
import '../reflection.dart'; | ||
import '../utils.dart'; | ||
|
||
/// The JavaScript `SassMixin` class. | ||
final JSClass mixinClass = () { | ||
var jsClass = createJSClass('sass.SassMixin', (Object self) { | ||
jsThrow(JsError( | ||
'It is not possible to construct a SassMixin through the JavaScript API')); | ||
}); | ||
|
||
getJSClass(SassMixin(Callable('f', '', (_) => sassNull))) | ||
.injectSuperclass(jsClass); | ||
return jsClass; | ||
}(); |
Oops, something went wrong.