mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:39:19 +00:00
Add pragma class to dart:core.
This class can be used to annotate declarations with tool specific hints. For example @pragma('vm:extern') can tell that a method is invoked from outside (e.g. via VM C API), which informs Kernel based tools not to tree-shake this method. Design doc (internal) https://docs.google.com/document/d/1yqje8uctBqITcwKxhebb0EHunY1bt0Qd4yZExrTHIW8/edit Change-Id: Icf2106accfb1167124582466a3a55486d432793d Reviewed-on: https://dart-review.googlesource.com/43062 Reviewed-by: Leaf Petersen <leafp@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
parent
94aa20dd07
commit
675048d0b6
|
@ -82,6 +82,7 @@ the assignment to `y`.
|
|||
* `BigInt` class added to support integers greater than 64-bits.
|
||||
* Deprecated the `proxy` annotation.
|
||||
* Added `Provisional` class and `provisional` field.
|
||||
* Added `pragma` annotation.
|
||||
* `RegExp` added static `escape` function.
|
||||
* The `Uri` class now correctly handles paths while running on Node.js on
|
||||
Windows.
|
||||
|
|
|
@ -214,3 +214,55 @@ class _Proxy {
|
|||
*/
|
||||
@deprecated
|
||||
const Object proxy = const _Proxy();
|
||||
|
||||
/**
|
||||
* A hint to tools.
|
||||
*
|
||||
* Tools that work with Dart programs may accept hints to guide their behavior
|
||||
* as `pragma` annotations on declarations.
|
||||
* Each tool decides which hints it accepts, what they mean, and whether and
|
||||
* how they apply to sub-parts of the annotated entity.
|
||||
*
|
||||
* Tools that recognize pragma hints should pick a pragma prefix to identify
|
||||
* the tool. They should recognize any hint with a [name] starting with their
|
||||
* prefix followed by `:` as if it was intended for that tool. A hint with a
|
||||
* prefix for another tool should be ignored (unless compatibility with that
|
||||
* other tool is a goal).
|
||||
*
|
||||
* A tool may recognize unprefixed names as well, if they would recognize that
|
||||
* name with their own prefix in front.
|
||||
*
|
||||
* If the hint can be parameterized, an extra [options] object can be added as well.
|
||||
*
|
||||
* For example:
|
||||
*
|
||||
* ```dart
|
||||
* @pragma('Tool:pragma-name', [param1, param2, ...])
|
||||
* class Foo { }
|
||||
*
|
||||
* @pragma('OtherTool:other-pragma')
|
||||
* void foo() { }
|
||||
* ```
|
||||
*
|
||||
* Here class Foo is annotated with a Tool specific pragma 'pragma-name' and
|
||||
* function foo is annotated with a pragma 'other-pragma' specific to OtherTool.
|
||||
*
|
||||
*/
|
||||
class pragma {
|
||||
/**
|
||||
* The name of the hint.
|
||||
*
|
||||
* A string that is recognized by one or more tools, or such a string prefixed
|
||||
* by a tool identifier and a colon, which is only recognized by that
|
||||
* particular tool.
|
||||
*/
|
||||
final String name;
|
||||
|
||||
/** Optional extra data parameterizing the hint. */
|
||||
final Object options;
|
||||
|
||||
/** Creates a hint named [name] with optional [options]. */
|
||||
const factory pragma(String name, [Object options]) = pragma._;
|
||||
|
||||
const pragma._(this.name, [this.options]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue