generateStrictModeCheck()
generateStrictModeCheck(
objectVar,allowedKeys,ctx,customMessage?):object
Experimental
Generates code to check for extra keys in strict mode.
Parametersβ
objectVar: stringβ
The variable name of the object
allowedKeys: string[]β
Array of allowed property names
ctx: GeneratorContextβ
The generator context
customMessage?: stringβ
Optional custom error message
Returns: objectβ
Generated code lines and updated context
code: string[]β
ctx: GeneratorContextβ
Sinceβ
2.0.0
Exampleβ
const result = generateStrictModeCheck("value", ["name", "age"], ctx);
// result.code = [
// 'for (var k in value) {',
// ' if (Object.prototype.hasOwnProperty.call(value, k)) {',
// ' if (k !== "name" && k !== "age") return "Unexpected property: " + k;',
// ' }',
// '}'
// ]