Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded default cases in switch, move to switch expressions #3753

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _test/test/dart2wasm_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'common/utils.dart';
const _testArgs = ['-c', 'dart2wasm'];

void main() {
group('Can run tests using dart2wasm', () {
group('Can run tests using dart2wasm', timeout: const Timeout.factor(2), () {
test('via build.yaml config flag', () async {
await expectTestsPass(
usePrecompiled: true,
Expand Down
92 changes: 39 additions & 53 deletions build_runner_core/lib/src/asset_graph/serialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,6 @@ class _WrappedAssetNode extends Object with ListMixin implements List {
.map((id) => serializer.findAssetIndex(id,
from: node.id, field: 'deletedBy'))
.toList(growable: false);
default:
throw RangeError.index(index, this);
}
}

Expand Down Expand Up @@ -399,28 +397,23 @@ class _WrappedGeneratedAssetNode extends _WrappedAssetNode {
Object? operator [](int index) {
if (index < _serializedOffset) return super[index];
var fieldId = _GeneratedField.values[index - _serializedOffset];
switch (fieldId) {
case _GeneratedField.primaryInput:
return serializer.findAssetIndex(generatedNode.primaryInput,
from: generatedNode.id, field: 'primaryInput');
case _GeneratedField.wasOutput:
return _serializeBool(generatedNode.wasOutput);
case _GeneratedField.isFailure:
return _serializeBool(generatedNode.isFailure);
case _GeneratedField.phaseNumber:
return generatedNode.phaseNumber;
case _GeneratedField.state:
return generatedNode.state.index;
case _GeneratedField.previousInputsDigest:
return _serializeDigest(generatedNode.previousInputsDigest);
case _GeneratedField.builderOptions:
return serializer.findAssetIndex(generatedNode.builderOptionsId,
from: generatedNode.id, field: 'builderOptions');
case _GeneratedField.isHidden:
return _serializeBool(generatedNode.isHidden);
default:
throw RangeError.index(index, this);
}
return switch (fieldId) {
_GeneratedField.primaryInput => serializer.findAssetIndex(
generatedNode.primaryInput,
from: generatedNode.id,
field: 'primaryInput'),
_GeneratedField.wasOutput => _serializeBool(generatedNode.wasOutput),
_GeneratedField.isFailure => _serializeBool(generatedNode.isFailure),
_GeneratedField.phaseNumber => generatedNode.phaseNumber,
_GeneratedField.state => generatedNode.state.index,
_GeneratedField.previousInputsDigest =>
_serializeDigest(generatedNode.previousInputsDigest),
_GeneratedField.builderOptions => serializer.findAssetIndex(
generatedNode.builderOptionsId,
from: generatedNode.id,
field: 'builderOptions'),
_GeneratedField.isHidden => _serializeBool(generatedNode.isHidden)
};
}
}

Expand All @@ -447,21 +440,15 @@ class _WrappedGlobAssetNode extends _WrappedAssetNode {
Object? operator [](int index) {
if (index < _serializedOffset) return super[index];
var fieldId = _GlobField.values[index - _serializedOffset];
switch (fieldId) {
case _GlobField.phaseNumber:
return globNode.phaseNumber;
case _GlobField.state:
return globNode.state.index;
case _GlobField.glob:
return globNode.glob.pattern;
case _GlobField.results:
return globNode.results!
.map((id) => serializer.findAssetIndex(id,
from: globNode.id, field: 'results'))
.toList(growable: false);
default:
throw RangeError.index(index, this);
}
return switch (fieldId) {
_GlobField.phaseNumber => globNode.phaseNumber,
_GlobField.state => globNode.state.index,
_GlobField.glob => globNode.glob.pattern,
_GlobField.results => globNode.results!
.map((id) => serializer.findAssetIndex(id,
from: globNode.id, field: 'results'))
.toList(growable: false)
};
}
}

Expand Down Expand Up @@ -489,20 +476,19 @@ class _WrappedPostProcessAnchorNode extends _WrappedAssetNode {
Object? operator [](int index) {
if (index < _serializedOffset) return super[index];
var fieldId = _PostAnchorField.values[index - _serializedOffset];
switch (fieldId) {
case _PostAnchorField.actionNumber:
return wrappedNode.actionNumber;
case _PostAnchorField.builderOptions:
return serializer.findAssetIndex(wrappedNode.builderOptionsId,
from: wrappedNode.id, field: 'builderOptions');
case _PostAnchorField.previousInputsDigest:
return _serializeDigest(wrappedNode.previousInputsDigest);
case _PostAnchorField.primaryInput:
return serializer.findAssetIndex(wrappedNode.primaryInput,
from: wrappedNode.id, field: 'primaryInput');
default:
throw RangeError.index(index, this);
}
return switch (fieldId) {
_PostAnchorField.actionNumber => wrappedNode.actionNumber,
_PostAnchorField.builderOptions => serializer.findAssetIndex(
wrappedNode.builderOptionsId,
from: wrappedNode.id,
field: 'builderOptions'),
_PostAnchorField.previousInputsDigest =>
_serializeDigest(wrappedNode.previousInputsDigest),
_PostAnchorField.primaryInput => serializer.findAssetIndex(
wrappedNode.primaryInput,
from: wrappedNode.id,
field: 'primaryInput')
};
}
}

Expand Down
Loading