Skip to content
Closed
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
20 changes: 19 additions & 1 deletion crates/bamts-compiler/src/checker/binder/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Binder<'_> {
self.class_instance_types.insert(type_symbol, instance);
self.class_instance_types.insert(value_symbol, instance);

let value = if self.intrinsics.has_lib(Lib::Es2015) {
let value = if self.intrinsics.has_lib(Lib::Es2015DateCore) {
self.types.union(&[number, string, instance])
} else {
self.types.union(&[number, string])
Expand Down Expand Up @@ -446,6 +446,24 @@ mod tests {
panic!("Date(value) must expose a union parameter");
};
assert_eq!(es2015_members.len(), 3);

let (core_model, core_diagnostics) = bound_with_libs(
"declare const d: Date;",
LibSet::from_lib_names(&["es5", "es2015.core"]),
);
assert!(core_diagnostics.is_empty(), "{core_diagnostics:?}");
let core_constructor = core_model.symbol_type(value_symbol(&core_model, "Date"));
let Type::ObjectType(core_constructor) = core_model.types().get(core_constructor) else {
panic!("Date value must expose an object constructor type");
};
let core_value_parameter = core_constructor.construct_signatures[1]
.signature
.parameters()[0]
.type_id();
let Type::Union(core_members) = core_model.types().get(core_value_parameter) else {
panic!("Date(value) must expose a union parameter");
};
assert_eq!(core_members.len(), 3);
}

#[test]
Expand Down
33 changes: 30 additions & 3 deletions crates/bamts-compiler/src/checker/intrinsic_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub(crate) enum Lib {
/// `lib.es2015.*.d.ts` — Proxy, Reflect, Map, Set, Symbol, Promise,
/// Iterable, Iterator, Generator, and friends.
Es2015,
/// The Date constructor overload declared by `lib.es2015.core.d.ts`.
/// This is tracked separately because the core fragment does not enable
/// the other ES2015 globals.
Es2015DateCore,
/// `lib.es2017.sharedmemory.d.ts` — `Atomics`, `SharedArrayBuffer`.
Es2017SharedMemory,
/// `lib.es2018.asynciterable.d.ts`, `lib.es2018.asyncgenerator.d.ts` —
Expand Down Expand Up @@ -78,7 +82,7 @@ impl LibSet {
pub(crate) const EMPTY: Self = Self(0);

/// The set containing every category — used when lib scoping is disabled.
pub(crate) const ALL: Self = Self((1 << 17) - 1);
pub(crate) const ALL: Self = Self((1 << 18) - 1);

#[must_use]
pub(crate) const fn contains(self, lib: Lib) -> bool {
Expand All @@ -105,7 +109,7 @@ impl LibSet {
.with(Lib::WebworkerImportscripts)
.with(Lib::Scripthost);
if (target as u8) >= (ScriptTarget::Es2015 as u8) {
set = set.with(Lib::Es2015);
set = set.with(Lib::Es2015).with(Lib::Es2015DateCore);
}
if (target as u8) >= (ScriptTarget::Es2017 as u8) {
set = set.with(Lib::Es2017SharedMemory);
Expand Down Expand Up @@ -139,12 +143,35 @@ impl LibSet {
let mut set = Self::EMPTY.with(Lib::Always).with(Lib::DecoratorsLegacy);
for name in names {
let lower = name.as_ref().to_ascii_lowercase();
if matches!(
lower.as_str(),
"es6"
| "es2015"
| "es7"
| "es2016"
| "es2017"
| "es2018"
| "es2019"
| "es2020"
| "es2021"
| "es2022"
| "es2023"
| "es2024"
| "es2025"
| "esnext"
| "es2015.core"
) {
set = set.with(Lib::Es2015DateCore);
}
match lower.as_str() {
"es5" | "es3" => {
set = set.with(Lib::Es5);
}
"es6" | "es2015" => {
set = set.with(Lib::Es5).with(Lib::Es2015);
set = set
.with(Lib::Es5)
.with(Lib::Es2015)
.with(Lib::Es2015DateCore);
}
"es7" | "es2016" => {
set = set.with(Lib::Es5).with(Lib::Es2015);
Expand Down
Loading