lt-script 1.0.5 → 1.0.7

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.
@@ -1,4 +1,5 @@
1
1
  import * as AST from '../parser/AST.js';
2
+ import { isNative } from '../natives/NativeLoader.js';
2
3
  class Scope {
3
4
  symbols = new Map();
4
5
  parent;
@@ -418,34 +419,29 @@ export class SemanticAnalyzer {
418
419
  if (expr.kind === AST.NodeType.Identifier) {
419
420
  const id = expr;
420
421
  const sym = this.currentScope.lookup(id.name);
421
- // Skip globals/builtins - only check if it looks like a user variable
422
- // FiveM/Lua has many globals, so we only warn for simple lowercase identifiers
423
- // that are not common Lua globals
424
- const luaGlobals = ['print', 'type', 'tostring', 'tonumber', 'pairs', 'ipairs',
422
+ // Lua core globals (standard library)
423
+ const luaCoreGlobals = [
424
+ 'print', 'type', 'tostring', 'tonumber', 'pairs', 'ipairs',
425
425
  'next', 'error', 'assert', 'pcall', 'xpcall', 'require',
426
426
  'table', 'string', 'math', 'os', 'io', 'coroutine', 'debug',
427
427
  'setmetatable', 'getmetatable', 'rawget', 'rawset', 'rawequal',
428
428
  'collectgarbage', 'dofile', 'load', 'loadfile', 'select',
429
429
  'unpack', '_G', '_VERSION', 'true', 'false', 'nil',
430
- // FiveM common globals
431
- 'Citizen', 'CreateThread', 'Wait', 'GetGameTimer', 'vector3',
432
- 'vector2', 'vector4', 'GetCurrentResourceName', 'exports',
433
- 'PlayerPedId', 'GetPlayerPed', 'GetEntityCoords', 'TriggerEvent',
434
- 'TriggerServerEvent', 'TriggerClientEvent', 'RegisterNetEvent',
435
- 'AddEventHandler', 'RegisterCommand', 'IsControlJustPressed',
436
- 'AddEventHandler', 'RegisterCommand', 'LocalPlayer', 'PlayerId',
437
- 'GetPlayerServerId', 'source', 'SetEntityHealth', 'ESX', 'QBCore',
438
- // Additional FiveM/Lua globals
439
- 'Config', 'Framework', 'MySQL', 'lib', 'cache', 'json',
440
- 'NetworkGetNetworkIdFromEntity', 'NetworkGetEntityFromNetworkId',
441
- 'GetPlayerPed', 'GetVehiclePedIsIn', 'IsPedInAnyVehicle',
442
- 'SetPedCanRagdoll', 'SetTimeout', 'SetInterval', 'ClearTimeout',
443
- 'GetHashKey', 'IsModelValid', 'RequestModel', 'HasModelLoaded'];
444
- if (!sym && !luaGlobals.includes(id.name)) {
445
- // Check if it's a type name (not a variable)
446
- if (!this.typeRegistry.has(id.name) && !this.typeAliasRegistry.has(id.name)) {
447
- throw new Error(`Undefined variable '${id.name}' at line ${id.line ?? 0}`);
430
+ // FiveM framework globals (not in natives.lt)
431
+ 'Citizen', 'exports', 'source', 'ESX', 'QBCore', 'Config',
432
+ 'Framework', 'MySQL', 'lib', 'cache', 'json', 'LocalPlayer',
433
+ 'vector2', 'vector3', 'vector4'
434
+ ];
435
+ if (!sym && !luaCoreGlobals.includes(id.name)) {
436
+ // Check if it's a type name
437
+ if (this.typeRegistry.has(id.name) || this.typeAliasRegistry.has(id.name)) {
438
+ return;
448
439
  }
440
+ // Check if it's a FiveM/CFX native (from natives.lt)
441
+ if (isNative(id.name)) {
442
+ return;
443
+ }
444
+ throw new Error(`Undefined variable '${id.name}' at line ${id.line ?? 0}`);
449
445
  }
450
446
  return;
451
447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lt-script",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "LT Language Compiler for FiveM",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,9 @@
25
25
  },
26
26
  "license": "MIT",
27
27
  "scripts": {
28
- "build": "tsc",
28
+ "generate:natives": "tsx tools/generate_native_names.ts",
29
+ "prebuild": "npm run generate:natives",
30
+ "build": "npm run prebuild && tsc",
29
31
  "dev": "tsc --watch",
30
32
  "test": "node dist/tests/run.js",
31
33
  "build:lt": "npm run build",