Files
sdk/pkg/dev_compiler/test/sourcemap/sourcemaps_ddk_suite.dart
T
Nate Bosch 2bbb2f3c1f Disallow implicit casts
Explicit casts make it easier to confidently navigate the code base and
apply refactorings which tighten types. This change exposes a number of
places where types can be tightened, but only the most trivial were
applied. For most places I added the explicit cast that would have
happened anyway and so behavior shouldn't be changing.

- Add the configuration which disallows implicit casts in the analyzer.
- Add explicit casts in almost all instances.
- Where the implicit cast was due to a local variable type on the left,
  change it to a `var` so the type is not repeated.
- In a few places add argument types where they were already applied on
  the parent type, and the subclass was unnecessarily loosening argument
  types to dynamic.
- In a few places where a method was defined with an implicit dynamic
  return but had an obvious and consistent return type, annotate the
  method instead of casting after calls to that method.

Change-Id: I90e11b1cc08ce69967ea5705b507d5758a8f668f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103381
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2019-05-22 00:33:39 +00:00

108 lines
3.3 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:dev_compiler/src/kernel/command.dart';
import 'package:front_end/src/api_unstable/ddc.dart' as fe;
import 'package:sourcemap_testing/src/stepping_helper.dart';
import 'package:testing/testing.dart';
import 'common.dart';
import 'ddc_common.dart';
Future<ChainContext> createContext(
Chain suite, Map<String, String> environment) async {
return SourceMapContext(environment);
}
class SourceMapContext extends ChainContextWithCleanupHelper
implements WithCompilerState {
final Map<String, String> environment;
@override
fe.InitializedCompilerState compilerState;
SourceMapContext(this.environment);
List<Step> _steps;
@override
List<Step> get steps {
return _steps ??= <Step>[
const Setup(),
Compile(DevCompilerRunner(this, debugging())),
const StepWithD8(),
CheckSteps(debugging()),
];
}
@override
bool debugging() => environment.containsKey("debug");
}
class DevCompilerRunner implements CompilerRunner {
final WithCompilerState context;
final bool debugging;
const DevCompilerRunner(this.context, [this.debugging = false]);
@override
Future<Null> run(Uri inputFile, Uri outputFile, Uri outWrapperFile) async {
Uri outDir = outputFile.resolve(".");
String outputFilename = outputFile.pathSegments.last;
File sdkJsFile = findInOutDir("gen/utils/dartdevc/js/es6/dart_sdk.js");
var jsSdkPath = sdkJsFile.uri;
File ddcSdkSummary = findInOutDir("gen/utils/dartdevc/kernel/ddc_sdk.dill");
List<String> args = <String>[
"--packages=${sdkRoot.uri.resolve(".packages").toFilePath()}",
"--modules=es6",
"--dart-sdk-summary=${ddcSdkSummary.path}",
"-o",
outputFile.toFilePath(),
inputFile.toFilePath()
];
bool succeeded = false;
try {
var result = await compile(args, compilerState: context.compilerState);
context.compilerState =
result.compilerState as fe.InitializedCompilerState;
succeeded = result.success;
} catch (e, s) {
print('Unhandled exception:');
print(e);
print(s);
}
if (!succeeded) {
var ddc = getDdcDir().uri.resolve("bin/dartdevc.dart");
throw "Error from ddc when executing with something like "
"$dartExecutable ${ddc.toFilePath()} --kernel "
"${args.reduce((value, element) => '$value "$element"')}";
}
var jsContent = File.fromUri(outputFile).readAsStringSync();
File.fromUri(outputFile).writeAsStringSync(jsContent.replaceFirst(
"from 'dart_sdk'", "from '${uriPathForwardSlashed(jsSdkPath)}'"));
if (debugging) {
createHtmlWrapper(
sdkJsFile, outputFile, jsContent, outputFilename, outDir);
}
var inputFileName = inputFile.pathSegments.last;
var inputFileNameNoExt =
inputFileName.substring(0, inputFileName.lastIndexOf("."));
File.fromUri(outWrapperFile).writeAsStringSync(
getWrapperContent(jsSdkPath, inputFileNameNoExt, outputFilename));
}
}
main(List<String> arguments) => runMe(arguments, createContext, "testing.json");