Select Page

Two Spread Operator Bugs In Adobe ColdFusion 2023

Ben Nadel
Published: June 28, 2024

I ran into two strange bugs this morning when attempting to use the Spread operator in Adobe ColdFusion (2021 and 2023). One bug prevents the CFML template from compiling; the other bug is just a completely nonsense outcome of the spread operation (at least compared to JavaScript).

gives the ... operator the lowest possible precedence

You can get around both of these bugs by storing the spreadable object into an intermediary variable:


	logLevels = {
		OFF:   { level: 0 },
		FATAL: { level: 100 },
		ERROR: { level: 200 },
		WARN:  { level: 300 },
		INFO:  { level: 400 },
		DEBUG: { level: 500 },
		TRACE: { level: 600 }
	};
	// Use an intermediary variable so as not to confuse the CFML compiler.
	targetLevel = logLevels.OFF;
	// Attempt to SPREAD the OFF properties into a new object.
	selectedLevel = {
		...targetLevel
	};
	writeDump( selectedLevel );

When using the ... operator with a naked variable, ColdFusion does what you expect it to. And, we end up with a new object that has a .level property.

I will open two separate bug tickets and leave them in the comments.

Want to use code from this post?
Check out the license.


https://bennadel.com/4674

Source: www.bennadel.com