rsnext/packages/next/build/webpack/plugins/webpack-conformance-plugin/utils/ast-utils.ts
Prateek Bhatnagar 16672a4353
Adding conformance checks (#10314)
* adding tests  for rect sync conformance check

* adding test for react sync script conformance check

* reverting yarn lock changes

* adding duplicate polyfill conformance

* bug fixes in dulpicate polyfill conformance check

* adding settings capability to conformance plugin

* removing minification check from server build

* bug fix

* settings for react sync script check
2020-03-02 22:53:18 +01:00

25 lines
754 B
TypeScript

import { types } from 'recast'
import { namedTypes } from 'ast-types'
export function isNodeCreatingScriptElement(node: namedTypes.CallExpression) {
const callee = node.callee as namedTypes.Identifier
if (callee.type !== 'Identifier') {
return false
}
const componentNode = node.arguments[0] as namedTypes.Literal
if (componentNode.type !== 'Literal') {
return false
}
// Next has pragma: __jsx.
return callee.name === '__jsx' && componentNode.value === 'script'
}
export function reducePropsToObject(
propsNode: types.namedTypes.ObjectExpression
) {
return propsNode.properties.reduce((originalProps, prop: any) => {
// @ts-ignore
originalProps[prop.key.name] = prop.value.value
return originalProps
}, {})
}