Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function validateOutputConfig(config: OutputConfig) {
invariant(
isUndefinedOrBoolean(config.minify),
CompilerValidationErrors.INVALID_MINIFY_PROPERTY,
[config.minify]
);
invariant(
isUndefinedOrBoolean(config.compat),
CompilerValidationErrors.INVALID_COMPAT_PROPERTY,
[config.compat]
);
invariant(
isUndefinedOrBoolean(config.sourcemap),
CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
[config.sourcemap]
);
if (!isUndefined(config.env)) {
invariant(isObject(config.env), CompilerValidationErrors.INVALID_ENV_PROPERTY, [
config.env,
]);
for (const [key, value] of Object.entries(config.env)) {
invariant(KNOWN_ENV.has(key), CompilerValidationErrors.UNKNOWN_ENV_ENTRY_KEY, [key]);
invariant(isString(value), CompilerValidationErrors.INVALID_ENV_ENTRY_VALUE, [
key,
value,
function validateOutputConfig(config: OutputConfig) {
invariant(
isUndefinedOrBoolean(config.minify),
CompilerValidationErrors.INVALID_MINIFY_PROPERTY,
[config.minify]
);
invariant(
isUndefinedOrBoolean(config.compat),
CompilerValidationErrors.INVALID_COMPAT_PROPERTY,
[config.compat]
);
invariant(
isUndefinedOrBoolean(config.sourcemap),
CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
[config.sourcemap]
);
if (!isUndefined(customProperties)) {
const { allowDefinition, resolution } = customProperties;
invariant(
isUndefined(allowDefinition) || isBoolean(allowDefinition),
CompilerValidationErrors.INVALID_ALLOWDEFINITION_PROPERTY,
[allowDefinition]
);
if (!isUndefined(resolution)) {
invariant(isObject(resolution), CompilerValidationErrors.INVALID_RESOLUTION_PROPERTY, [
resolution,
]);
const { type } = resolution;
invariant(
type === 'native' || type === 'module',
CompilerValidationErrors.INVALID_TYPE_PROPERTY,
[type]
);
}
}
}
export function validateOptions(options: CompilerOptions) {
invariant(!isUndefined(options), CompilerValidationErrors.MISSING_OPTIONS_OBJECT, [options]);
invariant(isString(options.name), CompilerValidationErrors.INVALID_NAME_PROPERTY, [
options.name,
]);
invariant(isString(options.namespace), CompilerValidationErrors.INVALID_NAMESPACE_PROPERTY, [
options.namespace,
]);
invariant(
!isUndefined(options.files) && !!Object.keys(options.files).length,
CompilerValidationErrors.INVALID_FILES_PROPERTY
);
for (const key of Object.keys(options.files)) {
const value = options.files[key];
invariant(
!isUndefined(value) && isString(value),
function validateStylesheetConfig(config: StylesheetConfig) {
const { customProperties } = config;
if (!isUndefined(customProperties)) {
const { allowDefinition, resolution } = customProperties;
invariant(
isUndefined(allowDefinition) || isBoolean(allowDefinition),
CompilerValidationErrors.INVALID_ALLOWDEFINITION_PROPERTY,
[allowDefinition]
);
if (!isUndefined(resolution)) {
invariant(isObject(resolution), CompilerValidationErrors.INVALID_RESOLUTION_PROPERTY, [
resolution,
]);
const { type } = resolution;
invariant(
type === 'native' || type === 'module',
CompilerValidationErrors.INVALID_TYPE_PROPERTY,
[type]
);
}
}
}
invariant(
isUndefinedOrBoolean(config.sourcemap),
CompilerValidationErrors.INVALID_SOURCEMAP_PROPERTY,
[config.sourcemap]
);
if (!isUndefined(config.env)) {
invariant(isObject(config.env), CompilerValidationErrors.INVALID_ENV_PROPERTY, [
config.env,
]);
for (const [key, value] of Object.entries(config.env)) {
invariant(KNOWN_ENV.has(key), CompilerValidationErrors.UNKNOWN_ENV_ENTRY_KEY, [key]);
invariant(isString(value), CompilerValidationErrors.INVALID_ENV_ENTRY_VALUE, [
key,
value,
]);
}
}
}
function validateArguments(src: string, filename: string) {
invariant(isString(src), TransformerErrors.INVALID_SOURCE, [src]);
invariant(isString(filename), TransformerErrors.INVALID_ID, [filename]);
}