Skip to content

Commit 2b30bfa

Browse files
trevoradecopybara-github
authored andcommitted
Update FeatureSet for clarity. Add BROWSER_2019 with explicitly removed features.
PiperOrigin-RevId: 839793743
1 parent 96665d3 commit 2b30bfa

2 files changed

Lines changed: 59 additions & 22 deletions

File tree

src/com/google/javascript/jscomp/CompilerOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public enum PropertyCollapseLevel {
141141
enum BrowserFeaturesetYear {
142142
YEAR_2012(2012, LanguageMode.ECMASCRIPT5_STRICT.toFeatureSet()),
143143
YEAR_2018(2018, LanguageMode.ECMASCRIPT_2016.toFeatureSet()),
144-
YEAR_2019(2019, LanguageMode.ECMASCRIPT_2017.toFeatureSet()),
144+
YEAR_2019(2019, FeatureSet.BROWSER_2019),
145145
YEAR_2020(2020, FeatureSet.BROWSER_2020),
146146
YEAR_2021(2021, FeatureSet.BROWSER_2021),
147147
YEAR_2022(2022, FeatureSet.BROWSER_2022),

src/com/google/javascript/jscomp/parsing/parser/FeatureSet.java

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,47 +98,76 @@ public final class FeatureSet implements Serializable {
9898
public static final FeatureSet ES_UNSUPPORTED =
9999
ES_UNSTABLE.with(LangVersion.ES_UNSUPPORTED.features());
100100

101-
public static final FeatureSet BROWSER_2020 =
102-
ES2019_MODULES.without(
103-
// https://kangax.github.io/compat-table/es2016plus/
104-
// All four of these are missing in Firefox 71 and lookbehind is missing in Safari 13.
101+
// NOTE: The BROWSER_20XX FeatureSets are the set of features supported by major browsers as of
102+
// January 1st of the given year. So, typically, take the year of the BFSY, subtract 1 to get
103+
// the correct ES20XX_MODULES FeatureSet as the base, then exclude any features as needed.
104+
//
105+
// Features and their supported browser versions can be found at
106+
// https://compat-table.github.io/compat-table/es2016plus/ or https://caniuse.com/
107+
//
108+
// The format for excluded features is: [Browser name] [version] (version release year)
109+
// Or, if a browser has no support yet: [Browser name] (unsupported)
110+
//
111+
// All excluded features should have a (year) this is greater than or equal to the BFSY.
112+
113+
public static final FeatureSet BROWSER_2019 =
114+
ES2018_MODULES.without(
115+
// NOTE: These 4 are excluded because, historically, we defined BROWSER_2019 as ES2017.
116+
// See cl/266708942 and cl/328623467 for context.
117+
// Chrome 60 (2017). Firefox 55 (2017). Safari 11.1 (2018).
118+
Feature.OBJECT_LITERALS_WITH_SPREAD,
119+
// Chrome 60 (2017). Firefox 55 (2017). Safari 11.1 (2018).
120+
Feature.OBJECT_PATTERN_REST,
121+
// Chrome 63 (2017). Firefox 57 (2017). Safari 12 (2018).
122+
Feature.ASYNC_GENERATORS,
123+
// Chrome 63 (2017). Firefox 57 (2017). Safari 12 (2018).
124+
Feature.FOR_AWAIT_OF,
125+
126+
// Chrome 62 (2017). Firefox 78 (2020). Safari 11.1 (2018).
105127
Feature.REGEXP_FLAG_S,
128+
// Chrome 62 (2017). Firefox 78 (2020). Safari 16.4 (2023).
106129
Feature.REGEXP_LOOKBEHIND,
130+
// Chrome 64 (2018). Firefox 78 (2020). Safari 11.1 (2018).
107131
Feature.REGEXP_NAMED_GROUPS,
132+
// Chrome 64 (2018). Firefox 78 (2020). Safari 11.1 (2018).
108133
Feature.REGEXP_UNICODE_PROPERTY_ESCAPE);
109134

135+
public static final FeatureSet BROWSER_2020 =
136+
ES2019_MODULES.without(
137+
// Chrome 62 (2017). Firefox 78 (2020). Safari 11.1 (2018).
138+
Feature.REGEXP_FLAG_S,
139+
// Chrome 64 (2018). Firefox 78 (2020). Safari 11.1 (2018).
140+
Feature.REGEXP_NAMED_GROUPS,
141+
// Chrome 64 (2018). Firefox 78 (2020). Safari 11.1 (2018).
142+
Feature.REGEXP_UNICODE_PROPERTY_ESCAPE,
143+
// Chrome 62 (2017). Firefox 78 (2020). Safari 16.4 (2023).
144+
Feature.REGEXP_LOOKBEHIND);
145+
110146
public static final FeatureSet BROWSER_2021 =
111147
ES2020_MODULES.without(
112-
// https://kangax.github.io/compat-table/es2016plus/
113-
// Regexp lookbehind is missing in Safari 14.
148+
// Chrome 62 (2017). Firefox 78 (2020). Safari 16.4 (2023).
114149
Feature.REGEXP_LOOKBEHIND);
115150

116151
public static final FeatureSet BROWSER_2022 =
117152
ES2021_MODULES.without(
118-
// https://kangax.github.io/compat-table/es2016plus/
119-
// Regexp lookbehind is still missing in Safari 15.
153+
// Chrome 62 (2017). Firefox 78 (2020). Safari 16.4 (2023).
120154
Feature.REGEXP_LOOKBEHIND);
121155

122156
public static final FeatureSet BROWSER_2023 =
123157
ES2021_MODULES.without(
124-
// https://kangax.github.io/compat-table/es2016plus/
125-
// Regexp lookbehind is still missing in Safari 16.2! It's in Safari TP though so
126-
// 2024 shouldn't need this awkward hack. We can't bump up to ES2022 here because
127-
// Safari 16.2 doesn't support class static blocks.
128158
// IMPORTANT: There is special casing for this feature and the ones excluded for
129159
// BROWSER_2020 above in RewritePolyfills.
130160
// If future Browser FeatureSet Year definitions have to remove any other features, then
131161
// we need to change the way that is done to avoid incorrect inclusion of polyfills.
162+
// Chrome 62 (2017). Firefox 78 (2020). Safari 16.4 (2023).
132163
Feature.REGEXP_LOOKBEHIND);
133164

134-
// According to https://compat-table.github.io/compat-table/es2016plus/ this should include all
135-
// features through ES2023. So once LangVersion.ES2023 is added, this should be updated to
136-
// include it.
165+
// Note: Only "Hashbang Grammar" is an ES2023 syntax feature. Its versions are:
166+
// Chrome 74 (2019). Firefox 67 (2019). Safari 13.1 (2020).
137167
public static final FeatureSet BROWSER_2024 = ES2021_MODULES;
138168

139-
// According to https://compat-table.github.io/compat-table/es2016plus/ this should include all
140-
// features through ES2024, except for the latest unicode versions for the /v regexp flag, which
141-
// isn't disqualifying. So once LangVersion.ES2024 is added, this should be updated to include it.
169+
// Note: Only "RegExp `v` flag" is an ES2024 syntax feature. Its versions are:
170+
// Chrome 112 (2023). Firefox 116 (2023). Safari 17 (2023).
142171
public static final FeatureSet BROWSER_2025 = ES2021_MODULES;
143172

144173
public static final FeatureSet ALL = ES_UNSUPPORTED.with(LangVersion.TYPESCRIPT.features());
@@ -230,15 +259,20 @@ public enum Feature {
230259

231260
// ES 2018 adds Regex Features:
232261
// https://github.com/tc39/proposal-regexp-dotall-flag
262+
// Note: Untranspilable.
233263
REGEXP_FLAG_S("RegExp flag 's'", LangVersion.ES2018),
234-
// https://github.com/tc39/proposal-regexp-lookbehind
235-
REGEXP_LOOKBEHIND("RegExp Lookbehind", LangVersion.ES2018),
236264
// https://github.com/tc39/proposal-regexp-named-groups
265+
// Note: Untranspilable.
237266
REGEXP_NAMED_GROUPS("RegExp named groups", LangVersion.ES2018),
238267
// https://github.com/tc39/proposal-regexp-unicode-property-escapes
268+
// Note: Untranspilable.
239269
REGEXP_UNICODE_PROPERTY_ESCAPE("RegExp unicode property escape", LangVersion.ES2018),
270+
// https://github.com/tc39/proposal-regexp-lookbehind
271+
// Note: Untranspilable.
272+
REGEXP_LOOKBEHIND("RegExp Lookbehind", LangVersion.ES2018),
240273

241274
// ES 2019 adds https://github.com/tc39/proposal-json-superset
275+
// Note: Untranspilable.
242276
UNESCAPED_UNICODE_LINE_OR_PARAGRAPH_SEP(
243277
"Unescaped unicode line or paragraph separator", LangVersion.ES2019),
244278

@@ -248,6 +282,7 @@ public enum Feature {
248282

249283
// ES 2020 Stage 4
250284
DYNAMIC_IMPORT("Dynamic module import", LangVersion.ES2020),
285+
// Note: Untranspilable.
251286
BIGINT("bigint", LangVersion.ES2020),
252287
IMPORT_META("import.meta", LangVersion.ES2020),
253288
NULL_COALESCE_OP("Nullish coalescing", LangVersion.ES2020),
@@ -258,6 +293,7 @@ public enum Feature {
258293
LOGICAL_ASSIGNMENT("Logical assignments", LangVersion.ES2021),
259294

260295
// ES 2022 adds https://github.com/tc39/proposal-regexp-match-indices
296+
// Note: Untranspilable.
261297
REGEXP_FLAG_D("RegExp flag 'd'", LangVersion.ES_NEXT),
262298

263299
// ES_NEXT: Features that are fully supported, but part of a language version that is not yet
@@ -281,7 +317,8 @@ public enum Feature {
281317
CLASS_STATIC_BLOCK("Class static block", LangVersion.ES_UNSTABLE),
282318

283319
// ES_UNSUPPORTED: Features that we can parse, but not yet supported in all checks
284-
// Part of ES2022. Support will improve as implementation progresses.
320+
321+
// ES 2022 adds https://github.com/tc39/proposal-class-fields
285322
PRIVATE_CLASS_PROPERTIES("Private class properties", LangVersion.ES_UNSUPPORTED),
286323

287324
// TypeScript type syntax that will never be implemented in browsers. Only used as an indicator

0 commit comments

Comments
 (0)