Skip to content

Commit 915b8ca

Browse files
eyebrowsoffireloic-sharma
authored andcommitted
Don't use sync*, as it is unimplemented in dart2wasm. (flutter#38149)
* Don't use sync*, as it is unimplemented in dart2wasm. * Address Joshua's comments. * Even more terse syntax, and change the name of the library
1 parent 29ddcd0 commit 915b8ca

File tree

7 files changed

+33
-36
lines changed

7 files changed

+33
-36
lines changed

third_party/web_locale_keymap/lib/web_locale_keymap/key_mappings.g.dart

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
77
//
8-
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
9-
// https://github.com/microsoft/vscode/tree/ab7ccc9e872dfcdfc429f8f2815109ec0ca926e3/src/vs/workbench/services/keybinding/browser/keyboardLayouts
8+
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
9+
// https://github.com/microsoft/vscode/tree/422b581e3802e30cfb780c21d9cc1a2cd0c9f0aa/src/vs/workbench/services/keybinding/browser/keyboardLayouts
1010
//
1111
// Edit the following files instead:
1212
//
1313
// - Script: lib/main.dart
1414
// - Templates: data/*.tmpl
1515
//
16-
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
16+
// See flutter/engine:flutter/tools/gen_web_locale_keymap/README.md for more information.
1717

1818
/// Used in the final mapping indicating the logical key should be derived from
1919
/// KeyboardEvent.keyCode.
@@ -100,16 +100,17 @@ bool isLetter(int charCode) {
100100
///
101101
/// This greatly reduces the entries needed in the final mapping.
102102
int? heuristicMapper(String code, String key) {
103-
// Digit code: return the digit.
103+
// Digit code: return the digit by event code.
104104
if (code.startsWith('Digit')) {
105105
assert(code.length == 6);
106106
return code.codeUnitAt(5); // The character immediately after 'Digit'
107107
}
108108
final int charCode = key.codeUnitAt(0);
109+
// Non-ascii: return the goal (i.e. US mapping by event code).
109110
if (key.length > 1 || !_isAscii(charCode)) {
110111
return kLayoutGoals[code]?.codeUnitAt(0);
111112
}
112-
// Letter key: return the letter.
113+
// Letter key: return the event key letter.
113114
if (isLetter(charCode)) {
114115
return key.toLowerCase().codeUnitAt(0);
115116
}
@@ -167,22 +168,20 @@ class _StringStream {
167168

168169
Map<String, int> _unmarshallCodeMap(_StringStream stream) {
169170
final int entryNum = stream.readIntAsVerbatim();
170-
return Map<String, int>.fromEntries((() sync* {
171-
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
172-
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
173-
}
174-
})());
171+
return <String, int>{
172+
for (int i = 0; i < entryNum; i++)
173+
stream.readEventKey(): stream.readIntAsChar(),
174+
};
175175
}
176176

177177
/// Decode a key mapping data out of the string.
178178
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
179179
final _StringStream stream = _StringStream(compressed);
180180
final int eventCodeNum = stream.readIntAsVerbatim();
181-
return Map<String, Map<String, int>>.fromEntries((() sync* {
182-
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
183-
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
184-
}
185-
})());
181+
return <String, Map<String, int>>{
182+
for (int i = 0; i < eventCodeNum; i++)
183+
stream.readEventCode() : _unmarshallCodeMap(stream),
184+
};
186185
}
187186

188187
/// Data for [LocaleKeymap] on Windows.

third_party/web_locale_keymap/test/test_cases.g.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
77
//
8-
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
8+
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
99
// https://github.com/microsoft/vscode/tree/@@@COMMIT_ID@@@/src/vs/workbench/services/keybinding/browser/keyboardLayouts
1010
//
1111
// Edit the following files instead:
1212
//
1313
// - Script: lib/main.dart
1414
// - Templates: data/*.tmpl
1515
//
16-
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
16+
// See flutter/engine:flutter/tools/gen_web_keyboard_keymap/README.md for more information.
1717

1818
import 'package:test/test.dart';
1919
import 'package:web_locale_keymap/web_locale_keymap.dart';

tools/gen_web_locale_keymap/bin/gen_web_locale_keymap.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import 'dart:io';
66

77
import 'package:args/args.dart';
8-
import 'package:gen_web_keyboard_layouts/benchmark_planner.dart';
9-
import 'package:gen_web_keyboard_layouts/common.dart';
10-
import 'package:gen_web_keyboard_layouts/github.dart';
11-
import 'package:gen_web_keyboard_layouts/layout_types.dart';
8+
import 'package:gen_web_keyboard_keymap/benchmark_planner.dart';
9+
import 'package:gen_web_keyboard_keymap/common.dart';
10+
import 'package:gen_web_keyboard_keymap/github.dart';
11+
import 'package:gen_web_keyboard_keymap/layout_types.dart';
1212
import 'package:path/path.dart' as path;
1313

1414
const String kEnvGithubToken = 'GITHUB_TOKEN';

tools/gen_web_locale_keymap/data/key_mappings.dart.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
77
//
8-
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
8+
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
99
// @@@COMMIT_URL@@@
1010
//
1111
// Edit the following files instead:
1212
//
1313
// - Script: lib/main.dart
1414
// - Templates: data/*.tmpl
1515
//
16-
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
16+
// See flutter/engine:flutter/tools/gen_web_locale_keymap/README.md for more information.
1717
@@@COMMON@@@
1818

1919
/// Data for [LocaleKeymap] on Windows.

tools/gen_web_locale_keymap/data/test_cases.dart.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
77
//
8-
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_layouts based on
8+
// This file is auto generated by flutter/engine:flutter/tools/gen_web_keyboard_keymap based on
99
// https://github.com/microsoft/vscode/tree/@@@COMMIT_ID@@@/src/vs/workbench/services/keybinding/browser/keyboardLayouts
1010
//
1111
// Edit the following files instead:
1212
//
1313
// - Script: lib/main.dart
1414
// - Templates: data/*.tmpl
1515
//
16-
// See flutter/engine:flutter/tools/gen_web_keyboard_layouts/README.md for more information.
16+
// See flutter/engine:flutter/tools/gen_web_keyboard_keymap/README.md for more information.
1717

1818
import 'package:test/test.dart';
1919
import 'package:web_locale_keymap/web_locale_keymap.dart';

tools/gen_web_locale_keymap/lib/common.dart

+8-10
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,20 @@ class _StringStream {
159159

160160
Map<String, int> _unmarshallCodeMap(_StringStream stream) {
161161
final int entryNum = stream.readIntAsVerbatim();
162-
return Map<String, int>.fromEntries((() sync* {
163-
for (int entryIndex = 0; entryIndex < entryNum; entryIndex += 1) {
164-
yield MapEntry<String, int>(stream.readEventKey(), stream.readIntAsChar());
165-
}
166-
})());
162+
return <String, int>{
163+
for (int i = 0; i < entryNum; i++)
164+
stream.readEventKey(): stream.readIntAsChar(),
165+
};
167166
}
168167

169168
/// Decode a key mapping data out of the string.
170169
Map<String, Map<String, int>> unmarshallMappingData(String compressed) {
171170
final _StringStream stream = _StringStream(compressed);
172171
final int eventCodeNum = stream.readIntAsVerbatim();
173-
return Map<String, Map<String, int>>.fromEntries((() sync* {
174-
for (int eventCodeIndex = 0; eventCodeIndex < eventCodeNum; eventCodeIndex += 1) {
175-
yield MapEntry<String, Map<String, int>>(stream.readEventCode(), _unmarshallCodeMap(stream));
176-
}
177-
})());
172+
return <String, Map<String, int>>{
173+
for (int i = 0; i < eventCodeNum; i++)
174+
stream.readEventCode() : _unmarshallCodeMap(stream),
175+
};
178176
}
179177

180178
/*@@@ SHARED SEGMENT END @@@*/

tools/gen_web_locale_keymap/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: gen_web_keyboard_layouts
1+
name: gen_web_keyboard_keymap
22
description: Generates keyboard layouts for Web from external sources.
33

44
environment:

0 commit comments

Comments
 (0)