From 5f752fe903beb87b2cd1a2e0d86fc3171f865bb5 Mon Sep 17 00:00:00 2001 From: centauri <83140718+centau@users.noreply.github.com> Date: Mon, 23 Jun 2025 21:36:51 +0100 Subject: [PATCH] Add flag to disable setting of default properties --- CHANGELOG.md | 1 + src/create.luau | 25 ++++++++++++++----------- src/flags.luau | 4 +++- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cde25a..ef3b525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `show()` now receives a source to its callback returning the current value of the condition. - Ignore `false` passed as a child. +- Flag `vide.defaults` to disable the setting of default properties. ### Changed diff --git a/src/create.luau b/src/create.luau index ebcbf54..193aa0f 100644 --- a/src/create.luau +++ b/src/create.luau @@ -3,23 +3,26 @@ local Instance = game and Instance or require "../test/mock".Instance :: never local defaults = require "./defaults" local apply = require "./apply" +local flags = require "./flags" local ctor_cache = {} :: { [string]: () -> Instance } setmetatable(ctor_cache :: any, { __index = function(self, class) - local ok, instance: Instance = pcall(Instance.new, class :: any) - if not ok then error(`invalid class name, could not create instance of class { class }`, 0) end - - local default: { [string]: unknown }? = defaults[class] - if default then - for i, v in next, default do - (instance :: any)[i] = v - end - end - local function ctor(properties: Props): Instance - return apply(instance:Clone(), properties) + local ok, instance: Instance = pcall(Instance.new, class :: any) + if not ok then error(`invalid class name { class }`, 0) end + + if flags.defaults then + local default: { [string]: unknown }? = defaults[class] + if default then + for i, v in default do + (instance :: any)[i] = v + end + end + end + + return apply(instance, properties) end self[class] = ctor diff --git a/src/flags.luau b/src/flags.luau index bc9424c..c4989d9 100644 --- a/src/flags.luau +++ b/src/flags.luau @@ -7,5 +7,7 @@ local is_O2 = inline_test() ~= "inline_test" return { strict = not is_O2, batch = false, - defer_nested_properties = true + defaults = true, + use_default_properties = true, + defer_nested_properties = true, }