@tilua/compiler 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ function __NAME__.findIndex(t, test)
19
19
  end
20
20
 
21
21
  function __NAME__.filter(t, test)
22
- local out = {}
22
+ local out = __ARRAY__({})
23
23
  for i = 1, #t do
24
24
  if test(t[i], i) then
25
25
  out[#out + 1] = t[i]
@@ -29,7 +29,7 @@ function __NAME__.filter(t, test)
29
29
  end
30
30
 
31
31
  function __NAME__.map(t, transform)
32
- local out = {}
32
+ local out = __ARRAY__({})
33
33
  for i = 1, #t do
34
34
  out[i] = transform(t[i], i)
35
35
  end
@@ -95,7 +95,7 @@ function __NAME__.join(t, separator)
95
95
  end
96
96
 
97
97
  function __NAME__.concat(t, ...)
98
- local out = {}
98
+ local out = __ARRAY__({})
99
99
  table.move(t, 1, #t, 1, out)
100
100
  for i = 1, select("#", ...) do
101
101
  local part = select(i, ...)
@@ -114,7 +114,7 @@ function __NAME__.slice(t, start, stop)
114
114
  if to < 0 then to = n + to + 1 end
115
115
  if from < 1 then from = 1 end
116
116
  if to > n then to = n end
117
- local out = {}
117
+ local out = __ARRAY__({})
118
118
  for i = from, to do
119
119
  out[#out + 1] = t[i]
120
120
  end
@@ -123,7 +123,7 @@ end
123
123
 
124
124
  -- One level, as JavaScript's `flat()` does by default.
125
125
  function __NAME__.flat(t)
126
- local out = {}
126
+ local out = __ARRAY__({})
127
127
  for i = 1, #t do
128
128
  local value = t[i]
129
129
  if type(value) == "table" then
@@ -5,7 +5,7 @@ local __NAME__ = {}
5
5
  -- follow the named ones. With no one order to give (`known` is nil), every
6
6
  -- key is listed, in the order `pairs` walks them.
7
7
  local function keysOf(known, open, t)
8
- local out = {}
8
+ local out = __ARRAY__({})
9
9
  if known == nil then
10
10
  for key in pairs(t) do
11
11
  out[#out + 1] = key
@@ -37,7 +37,7 @@ end
37
37
  -- rather than moving everything after it up one.
38
38
  function __NAME__.values(known, open, t)
39
39
  local keys = keysOf(known, open, t)
40
- local out = {}
40
+ local out = __ARRAY__({})
41
41
  for i = 1, #keys do
42
42
  out[i] = t[keys[i]]
43
43
  end
@@ -46,9 +46,48 @@ end
46
46
 
47
47
  function __NAME__.entries(known, open, t)
48
48
  local keys = keysOf(known, open, t)
49
- local out = {}
49
+ local out = __ARRAY__({})
50
50
  for i = 1, #keys do
51
- out[i] = { keys[i], t[keys[i]] }
51
+ out[i] = __ARRAY__({ keys[i], t[keys[i]] })
52
52
  end
53
53
  return out
54
54
  end
55
+
56
+ -- JavaScript's `Object` functions, as methods of the table they take first.
57
+ -- `known` and `open` are handed to every method here; these need neither.
58
+
59
+ -- The table's own member, not one its metatable's `__index` lends it.
60
+ function __NAME__.hasOwn(known, open, t, key)
61
+ return rawget(t, key) ~= nil
62
+ end
63
+
64
+ function __NAME__.hasOwnProperty(known, open, t, key)
65
+ return rawget(t, key) ~= nil
66
+ end
67
+
68
+ -- Each source's members onto `t`, later sources over earlier ones; a `nil`
69
+ -- source is skipped, as JavaScript skips `null`.
70
+ function __NAME__.assign(known, open, t, ...)
71
+ for i = 1, select("#", ...) do
72
+ local source = select(i, ...)
73
+ if source ~= nil then
74
+ for key, value in pairs(source) do
75
+ t[key] = value
76
+ end
77
+ end
78
+ end
79
+ return t
80
+ end
81
+
82
+ -- Luau freezes a table in place. Lua 5.1 has no way to, and the table is
83
+ -- answered as it is.
84
+ function __NAME__.freeze(known, open, t)
85
+ if table.freeze ~= nil and not table.isfrozen(t) then
86
+ table.freeze(t)
87
+ end
88
+ return t
89
+ end
90
+
91
+ function __NAME__.isFrozen(known, open, t)
92
+ return table.isfrozen ~= nil and table.isfrozen(t)
93
+ end
@@ -88,7 +88,7 @@ local function values(...)
88
88
  if select("#", ...) <= 1 and (...) == nil then
89
89
  return nil
90
90
  end
91
- return { ... }
91
+ return __ARRAY__({ ... })
92
92
  end
93
93
 
94
94
  function __NAME__.find(s, pattern, init, plain)
@@ -107,7 +107,7 @@ function __NAME__.byte(s, i, j)
107
107
  if j == nil then
108
108
  return (string.byte(s, i))
109
109
  end
110
- return { string.byte(s, i, j) }
110
+ return __ARRAY__({ string.byte(s, i, j) })
111
111
  end
112
112
 
113
113
  -- An iterator function: each call is one match's captures, as an array.