Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function componentPropType(props, key, componentName, location, propFullName) {
const prop = props[key];
const propName = propFullName || key;
let message;
if (prop == null) {
if (isRequired) {
message =
`The ${location} \`${propName}\` is marked as required in \`${componentName}\`, ` +
`but its value is \`${typeof prop}\`.`;
}
} else if (!isValidElementType(prop)) {
const preciseType = typeof prop;
message =
`Invalid ${location} \`${propName}\` of type \`${preciseType}\` ` +
`supplied to \`${componentName}\`, expected a component.`;
}
if (message != null) {
// change error message slightly on every check to prevent caching when testing
// which would not trigger console errors on subsequent fails
return new Error(`${message}${process.env.NODE_ENV === 'test' ? Date.now() : ''}`);
}
return null;
};
}
function constructWithOptions(componentConstructor, tag) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EMPTY_OBJECT;
if (!isValidElementType(tag)) {
throw new StyledComponentsError(1, String(tag));
}
/* This is callable directly as a template function */
// $FlowFixMe: Not typed to avoid destructuring arguments
var templateFunction = function templateFunction() {
return componentConstructor(tag, options, css.apply(undefined, arguments));
};
/* If config methods are called, wrap up a new template function and merge options */
templateFunction.withConfig = function(config) {
return constructWithOptions(componentConstructor, tag, _extends({}, options, config));
};
/* Modify/inject new props at runtime */
templateFunction.attrs = function(attrs) {
export function toObjectOverride(
override: OverrideT,
): OverrideObjectT {
if (isValidElementType(override)) {
return {
// eslint-disable-next-line flowtype/no-weak-types
component: ((override: any): React.ComponentType),
};
}
// Flow can't figure out that typeof 'function' above will
// catch React.StatelessFunctionalComponent
// (probably related to https://github.com/facebook/flow/issues/6666)
// eslint-disable-next-line flowtype/no-weak-types
return ((override || {}: any): OverrideObjectT);
}
export async function isPageStatic(
page: string,
serverBundle: string,
runtimeEnvConfig: any
): Promise<{
static?: boolean
prerender?: boolean
isHybridAmp?: boolean
prerenderRoutes?: string[] | undefined
}> {
try {
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig)
const mod = require(serverBundle)
const Comp = mod.default || mod
if (!Comp || !isValidElementType(Comp) || typeof Comp === 'string') {
throw new Error('INVALID_DEFAULT_EXPORT')
}
const hasGetInitialProps = !!(Comp as any).getInitialProps
const hasStaticProps = !!mod.unstable_getStaticProps
const hasStaticPaths = !!mod.unstable_getStaticPaths
const hasLegacyStaticParams = !!mod.unstable_getStaticParams
if (hasLegacyStaticParams) {
throw new Error(
`unstable_getStaticParams was replaced with unstable_getStaticPaths. Please update your code.`
)
}
// A page cannot be prerendered _and_ define a data requirement. That's
// contradictory!
let selector = `.${className}`;
if (styled) {
// If `styled` wraps another component and not a primitive,
// get its class name to create a more specific selector
// it'll ensure that styles are overridden properly
if (options.evaluate && t.isIdentifier(styled.component.node)) {
let { value } = evaluate(
styled.component,
t,
state.file.opts.filename,
undefined,
options
);
while (isValidElementType(value) && value.__linaria) {
selector += `.${value.__linaria.className}`;
value = value.__linaria.extends;
}
}
const props = [];
props.push(
t.objectProperty(t.identifier('name'), t.stringLiteral(displayName))
);
props.push(
t.objectProperty(t.identifier('class'), t.stringLiteral(className))
);
// If we found any interpolations, also pass them so they can be applied
`The CSS cannot contain JavaScript expressions when using the 'css' tag. To evaluate the expressions at build time, pass 'evaluate: true' to the babel plugin.`
);
}
}
}
});
let selector = `.${className}`;
if (styled) {
// If `styled` wraps another component and not a primitive,
// get its class name to create a more specific selector
// it'll ensure that styles are overridden properly
if (options.evaluate && types.isIdentifier(styled.component.node)) {
let value = valueCache.get(styled.component.node.name);
while (isValidElementType(value) && hasMeta(value)) {
selector += `.${value.__linaria.className}`;
value = value.__linaria.extends;
}
}
const props = [];
props.push(
types.objectProperty(
types.identifier('name'),
types.stringLiteral(displayName!)
)
);
props.push(
types.objectProperty(
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
if (!ReactIs.isValidElementType(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
}
return null;
}
return createChainableTypeChecker(validate);
function checkType(isRequired, props, propName, componentName, location, propFullName) {
const val = props[propName];
if (val === null || val === undefined) {
if (isRequired) {
if (val === null) {
return new PropTypeError(`The ${location} '${propFullName}' is marked as required in '${componentName}', but its value is 'null'.`);
}
return new PropTypeError(`The ${location} '${propFullName}' is marked as required in '${componentName}', but its value is 'undefined'.`);
}
} else if (!isValidElementType(val)) {
return new PropTypeError(`Invalid ${location} '${propFullName}' supplied to ${componentName}. ` +
"Expected a string (for built-in components) or a class/function (for composite components).");
}
return null;
}
isValidElementType(object) {
return !!object && isValidElementType(object);
}
BodyComponent: (props, propName) => {
if (props[propName] && !isValidElementType(props[propName])) {
return new Error(
`Invalid prop 'components.BodyComponent' supplied to 'Tooltip': the prop is not a valid React component`
);
}
return null;
},
TooltipWrapperComponent: (props, propName) => {