c768f80a96
Calls to methods annotated with `@pragma('dart2js:resource-identifier')` are tracked, with their primitive constant arguments, through to the `.js` file which contains the call.
- JavaScript annotations are attached to the JavaScript AST node for
the call.
- At the time of `.js` file printing, the JavaScript annotations are
collected and attributed to the file. This allows the construction
of a map from `.js` files to the 'resource identifiers' contained in
the file.
- Alongside the `main.js` file the resource identifiers are emitted in
a file called `main.js.resources.json`. This is controlled by the
`--write-resources` command line option.
- Serialization of JavaScript ASTs now serializes the attached
JavaScript annotations.
- The internal method used to implement deferred library loading is
annotated, to allow analysis of which deferred library parts load
other libraries.
pkg/js_ast was tweaked to make the pkg/js_ast was tweaked to make the
- pkg/js_ast was tweaked to make propagating the JavaScript annotations through the async transforms easier.
TODO:
- Annotate const constructors
- Add golden-style tests
Change-Id: Iea77550e22ee98f81dca61dfd713c09f734583d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284492
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
4.0 KiB
4.0 KiB
Resource Identifiers
Content TBD. Work in progress and details in flux.
Example output
TODO: Reference goldens in tests rather than keep the example below.
The call to loadDeferredLibrary in the Dart js_runtime is annotated with
@pragma('dart2js:resource-identifier'). This means that an app that uses
deferred loaded libraries will generate a section in the .resources.json.
In the Dart sdk directory, compile:
dart compile js --write-resources --out=somedir/o.js \
benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart
somedir/o.js.resource_identifiers.json:
{
"environment": {
"dart.web.assertions_enabled": "false"
},
"identifiers": [
{
"name": "loadDeferredLibrary",
"uri": "org-dartlang-sdk:///lib/_internal/js_runtime/lib/js_helper.dart",
"nonconstant": false,
"files": [
{
"filename": "o.js",
"references": [
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 15,
"column": 17
},
"1": "lib_BigIntParsePrint",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 16,
"column": 56
},
"1": "lib_ListCopy",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 17,
"column": 54
},
"1": "lib_MapCopy",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 18,
"column": 46
},
"1": "lib_MD5",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 19,
"column": 62
},
"1": "lib_RuntimeType",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 20,
"column": 48
},
"1": "lib_SHA1",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 21,
"column": 52
},
"1": "lib_SHA256",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 23,
"column": 17
},
"1": "lib_SkeletalAnimation",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 25,
"column": 17
},
"1": "lib_SkeletalAnimationSIMD",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 27,
"column": 17
},
"1": "lib_TypedDataDuplicate",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 28,
"column": 60
},
"1": "lib_Utf8Decode",
"2": 0
},
{
"@": {
"uri": "benchmarks/OmnibusDeferred/dart/OmnibusDeferred.dart",
"line": 29,
"column": 60
},
"1": "lib_Utf8Encode",
"2": 0
}
]
}
]
}
]
}