Made Luau Polyfill non-strict

This commit is contained in:
Allan Jeremy 2022-06-06 15:04:46 +03:00
parent b967fd0385
commit 3fcef32b4c

View file

@ -1,4 +1,4 @@
--!strict --!nonstrict
-- #region Array -- #region Array
-- Array related -- Array related
local Array = {} local Array = {}
@ -572,17 +572,17 @@ local function coerceToMap(mapLike: Map<any, any> | Table<any, any>): Map<any, a
or Map.new(Object.entries(mapLike)) -- ROBLOX: order is not preserved or Map.new(Object.entries(mapLike)) -- ROBLOX: order is not preserved
end end
local function coerceToTable(mapLike: Map<any, any> | Table<any, any>): Table<any, any> -- local function coerceToTable(mapLike: Map<any, any> | Table<any, any>): Table<any, any>
if not instanceOf(mapLike, Map) then -- if not instanceOf(mapLike, Map) then
return mapLike -- return mapLike
end -- end
-- create table from map -- -- create table from map
return Array.reduce(mapLike:entries(), function(tbl, entry) -- return Array.reduce(mapLike:entries(), function(tbl, entry)
tbl[entry[1]] = entry[2] -- tbl[entry[1]] = entry[2]
return tbl -- return tbl
end, {}) -- end, {})
end -- end
-- #region Tests to verify it works as expected -- #region Tests to verify it works as expected
local function it(description: string, fn: () -> ()) local function it(description: string, fn: () -> ())
@ -888,31 +888,31 @@ end)
-- #endregion -- #endregion
-- #region [Child Describe] "Integration Tests" -- #region [Child Describe] "Integration Tests"
it("MDN Examples", function() -- it("MDN Examples", function()
local myMap = Map.new() :: Map<string | Object | Function, string> -- local myMap = Map.new() :: Map<string | Object | Function, string>
local keyString = "a string" -- local keyString = "a string"
local keyObj = {} -- local keyObj = {}
local keyFunc = function() end -- local keyFunc = function() end
-- setting the values -- -- setting the values
myMap:set(keyString, "value associated with 'a string'") -- myMap:set(keyString, "value associated with 'a string'")
myMap:set(keyObj, "value associated with keyObj") -- myMap:set(keyObj, "value associated with keyObj")
myMap:set(keyFunc, "value associated with keyFunc") -- myMap:set(keyFunc, "value associated with keyFunc")
assert(myMap.size == 3) -- assert(myMap.size == 3)
-- getting the values -- -- getting the values
assert(myMap:get(keyString) == "value associated with 'a string'") -- assert(myMap:get(keyString) == "value associated with 'a string'")
assert(myMap:get(keyObj) == "value associated with keyObj") -- assert(myMap:get(keyObj) == "value associated with keyObj")
assert(myMap:get(keyFunc) == "value associated with keyFunc") -- assert(myMap:get(keyFunc) == "value associated with keyFunc")
assert(myMap:get("a string") == "value associated with 'a string'") -- assert(myMap:get("a string") == "value associated with 'a string'")
assert(myMap:get({}) == nil) -- nil, because keyObj !== {} -- assert(myMap:get({}) == nil) -- nil, because keyObj !== {}
assert(myMap:get(function() -- nil because keyFunc !== function () {} -- assert(myMap:get(function() -- nil because keyFunc !== function () {}
end) == nil) -- end) == nil)
end) -- end)
it("handles non-traditional keys", function() it("handles non-traditional keys", function()
local myMap = Map.new() :: Map<boolean | number | string, string> local myMap = Map.new() :: Map<boolean | number | string, string>