prettier pass: don't use es5 trailing comma

This commit is contained in:
Gaëtan Renaudeau 2017-07-04 18:15:29 +02:00
parent 890f739a3d
commit b506c56061
30 changed files with 115 additions and 112 deletions

View File

@ -6,7 +6,7 @@
"scripts": {
"postinstall": "lerna bootstrap && ./packages/undo-unsupported-symlinks.sh",
"watch": "lerna run watch --stream --no-sort",
"prettier": "prettier --trailing-comma es5 --write 'packages/{gl-react,gl-react-dom,gl-react-expo,gl-react-headless,gl-react-native}/src/*.js'",
"prettier": "prettier --write 'packages/{gl-react,gl-react-dom,gl-react-expo,gl-react-headless,gl-react-native}/src/*.js'",
"flow": "cd packages/gl-react && flow --quiet",
"test": "cd packages/tests && yarn test",
"test-rewrite-snapshots": "cd packages/tests && yarn test -- -u"

View File

@ -16,7 +16,7 @@ type WebGLContextAttributes = {
premultipliedAlpha?: boolean,
preserveDrawingBuffer?: boolean,
preferLowPowerToHighPerformance?: boolean,
failIfMajorPerformanceCaveat?: boolean,
failIfMajorPerformanceCaveat?: boolean
};
const propTypes = {
@ -28,7 +28,7 @@ const propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
style: PropTypes.object,
pixelRatio: PropTypes.number,
pixelRatio: PropTypes.number
};
export default class GLViewDOM extends Component {
@ -42,7 +42,7 @@ export default class GLViewDOM extends Component {
width: number,
height: number,
style?: any,
debug?: number,
debug?: number
};
static propTypes = propTypes;
webglContextAttributes: WebGLContextAttributes;

View File

@ -22,5 +22,5 @@ export const Surface = createSurface({
RenderLessElement,
mapRenderableContent,
requestFrame: raf,
cancelFrame: raf.cancel,
cancelFrame: raf.cancel
});

View File

@ -38,14 +38,14 @@ export default class ExponentGLObjectTextureLoader extends TextureLoader<
promise: NativeModules.ExponentGLObjectManager
.createObjectAsync({
exglCtxId,
texture,
texture
})
.then(({ exglObjId }) => {
if (disposed) return;
const webglTexture = new WebGLTexture(exglObjId);
this.textures.set(key, webglTexture);
return webglTexture;
}),
})
};
this.loads.set(key, d);
return d;

View File

@ -9,7 +9,7 @@ type Asset = {
width: number,
height: number,
uri: string,
localUri: string,
localUri: string
};
const hash = (module: number | { uri: string }) =>
@ -37,9 +37,9 @@ const remoteAsset = (uri: string) => {
uri,
`ExponentAsset-${key}${ext}`,
{
cache: true,
cache: true
}
),
)
]).then(([size, asset]) => ({ ...size, uri, localUri: asset.uri }));
remoteAssetCache[key] = promise;
return promise;
@ -96,7 +96,7 @@ export default class ExponentTextureLoader extends TextureLoader<*> {
dispose() {
ignored = true;
},
promise,
promise
};
this.loads.set(key, d);
return d;

View File

@ -6,14 +6,14 @@ import { GLView as EXGLView } from "expo";
const propTypes = {
onContextCreate: PropTypes.func.isRequired,
style: PropTypes.any,
style: PropTypes.any
};
export default class GLViewNative extends Component {
props: {
onContextCreate: (gl: WebGLRenderingContext) => void,
style?: any,
children?: any,
children?: any
};
static propTypes = propTypes;
@ -37,8 +37,8 @@ export default class GLViewNative extends Component {
flex: 1,
position: "absolute",
top: 0,
left: 0,
},
left: 0
}
]}
onContextCreate={onContextCreate}
/>

View File

@ -26,5 +26,5 @@ GLImage.prototype = {
if (this.onload) this.onload();
});
}
},
}
};

View File

@ -14,5 +14,5 @@ export const Surface = createSurface({
GLView,
RenderLessElement,
requestFrame: global.requestAnimationFrame,
cancelFrame: global.cancelAnimationFrame,
cancelFrame: global.cancelAnimationFrame
});

View File

@ -18,7 +18,7 @@ type WebGLContextAttributes = {
premultipliedAlpha?: boolean,
preserveDrawingBuffer?: boolean,
preferLowPowerToHighPerformance?: boolean,
failIfMajorPerformanceCaveat?: boolean,
failIfMajorPerformanceCaveat?: boolean
};
const propTypes = {
@ -28,7 +28,7 @@ const propTypes = {
onContextFailure: PropTypes.func.isRequired,
webglContextAttributes: PropTypes.object,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
height: PropTypes.number.isRequired
};
class GLView extends Component {
@ -39,7 +39,7 @@ class GLView extends Component {
onContextRestored: (gl: ?WebGLRenderingContext) => void,
webglContextAttributes?: WebGLContextAttributes,
width: number,
height: number,
height: number
};
static propTypes = propTypes;
webglContextAttributes: WebGLContextAttributes;
@ -55,7 +55,7 @@ class GLView extends Component {
const {
webglContextAttributes,
onContextCreate,
onContextFailure,
onContextFailure
} = this.props;
const gl: ?WebGLRenderingContext = getContext(
this.canvas,
@ -110,7 +110,7 @@ class GLView extends Component {
class RenderLessElement extends Component {
static propTypes = {
children: PropTypes.any,
children: PropTypes.any
};
// we keep ref so we can actually mapRenderableContent() on refs.
// These are all escape hatch for testing.
@ -137,7 +137,7 @@ class RenderLessElement extends Component {
: component => {
cloneRef(component);
originalRef(component);
},
}
});
})}
</span>
@ -151,5 +151,5 @@ export const Surface = createSurface({
// $FlowFixMe trust me flow xD
mapRenderableContent: (el: RenderLessElement) => el.getFirstChild(),
requestFrame: raf,
cancelFrame: raf.cancel,
cancelFrame: raf.cancel
});

View File

@ -8,7 +8,7 @@ import {
View,
ViewPropTypes,
Platform,
requireNativeComponent,
requireNativeComponent
} from "react-native";
// A component that acts as an OpenGL render target.
@ -26,11 +26,11 @@ export default class EXGLView extends React.Component {
// [iOS only] Number of samples for Apple"s built-in multisampling.
msaaSamples: PropTypes.number,
...ViewPropTypes,
...ViewPropTypes
};
static defaultProps = {
msaaSamples: 4,
msaaSamples: 4
};
render() {
@ -63,7 +63,7 @@ export default class EXGLView extends React.Component {
};
static NativeView = requireNativeComponent("EXGLView", EXGLView, {
nativeOnly: { onSurfaceCreate: true },
nativeOnly: { onSurfaceCreate: true }
});
}
@ -142,7 +142,7 @@ const wrapMethods = gl => {
[gl.FRAMEBUFFER_BINDING]: WebGLFramebuffer,
[gl.RENDERBUFFER_BINDING]: WebGLRenderbuffer,
[gl.TEXTURE_BINDING_2D]: WebGLTexture,
[gl.TEXTURE_BINDING_CUBE_MAP]: WebGLTexture,
[gl.TEXTURE_BINDING_CUBE_MAP]: WebGLTexture
};
wrap("getParameter", orig => pname => {
let ret = orig.call(gl, pname);
@ -311,7 +311,7 @@ const wrapMethods = gl => {
"vertexAttrib1fv",
"vertexAttrib2fv",
"vertexAttrib3fv",
"vertexAttrib4fv",
"vertexAttrib4fv"
],
orig => (index, val) => orig.call(gl, index, new Float32Array(val))
);

View File

@ -46,5 +46,5 @@ const load = (source: ImageSource): Promise<number> => {
};
export default {
load,
load
};

View File

@ -6,14 +6,14 @@ import EXGLView from "./EXGLView";
const propTypes = {
onContextCreate: PropTypes.func.isRequired,
style: PropTypes.any,
style: PropTypes.any
};
export default class GLViewNative extends Component {
props: {
onContextCreate: (gl: WebGLRenderingContext) => void,
style?: any,
children?: any,
children?: any
};
static propTypes = propTypes;
@ -37,8 +37,8 @@ export default class GLViewNative extends Component {
flex: 1,
position: "absolute",
top: 0,
left: 0,
},
left: 0
}
]}
onContextCreate={onContextCreate}
/>

View File

@ -28,5 +28,5 @@ GLImage.prototype = {
if (this.onload) this.onload();
});
}
},
}
};

View File

@ -42,7 +42,7 @@ export default class ImageSourceTextureLoader extends TextureLoader<
texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, {
glAssetId,
glAssetId
});
this.textures.set(glAssetId, texture);
}

View File

@ -15,5 +15,5 @@ export const Surface = createSurface({
GLView,
RenderLessElement,
requestFrame: global.requestAnimationFrame,
cancelFrame: global.cancelAnimationFrame,
cancelFrame: global.cancelAnimationFrame
});

View File

@ -11,7 +11,7 @@ import type { NDArray } from "ndarray";
type Props = {|
children?: React.Element<*> | ((redraw?: () => void) => React.Element<*>),
uniform?: string,
index: number,
index: number
|};
/**
@ -47,21 +47,21 @@ export default class Bus extends Component<{ index: number }, Props, void> {
props: Props;
context: {
glParent: Surface | Node,
glSurface: Surface,
glSurface: Surface
};
dependents: Array<Node | Surface> = [];
static defaultProps = {
index: 0,
index: 0
};
static contextTypes = {
glParent: PropTypes.object.isRequired,
glSurface: PropTypes.object.isRequired,
glSurface: PropTypes.object.isRequired
};
static childContextTypes = {
glParent: PropTypes.object.isRequired,
glParent: PropTypes.object.isRequired
};
componentWillMount() {
@ -111,7 +111,7 @@ export default class Bus extends Component<{ index: number }, Props, void> {
getChildContext(): { glParent: Bus } {
return {
glParent: this,
glParent: this
};
}
@ -205,7 +205,7 @@ export default class Bus extends Component<{ index: number }, Props, void> {
render() {
const { children } = this.props;
const {
glSurface: { RenderLessElement, mapRenderableContent },
glSurface: { RenderLessElement, mapRenderableContent }
} = this.context;
return (
<RenderLessElement ref={mapRenderableContent ? this.onRef : undefined}>

View File

@ -4,7 +4,7 @@ import Node from "./Node";
import copyShader from "./copyShader";
type Props = {|
children?: any,
children?: any
|};
/**

View File

@ -4,7 +4,7 @@ import Node from "./Node";
import copyShader from "./copyShader";
type Props = {|
children?: any,
children?: any
|};
/**

View File

@ -10,7 +10,7 @@ import Shaders, {
isShaderIdentifier,
ensureShaderDefinition,
shaderDefinitionToShaderInfo,
shaderInfoEquals,
shaderInfoEquals
} from "./Shaders";
import invariantNoDependentsLoop from "./helpers/invariantNoDependentsLoop";
import genId from "./genId";
@ -34,7 +34,7 @@ const blendFuncAliases = {
"one minus constant color": "ONE_MINUS_CONSTANT_COLOR",
"constant alpha": "CONSTANT_ALPHA",
"one minus constant alpha": "ONE_MINUS_CONSTANT_ALPHA",
"src alpha saturate": "SRC_ALPHA_SATURATE",
"src alpha saturate": "SRC_ALPHA_SATURATE"
};
/**
@ -63,7 +63,7 @@ type WrapMode = "clamp to edge" | "repeat" | "mirrored repeat";
*/
type TextureOptions = {
interpolation: Interpolation,
wrap: [WrapMode, WrapMode] | WrapMode,
wrap: [WrapMode, WrapMode] | WrapMode
};
/**
@ -93,7 +93,7 @@ type BlendFunc = $Keys<typeof blendFuncAliases>;
*/
type BlendFuncSrcDst = {|
src: BlendFunc,
dst: BlendFunc,
dst: BlendFunc
|};
/**
@ -105,7 +105,7 @@ type Vec4 = [number, number, number, number];
* The GL clear mode.
*/
type Clear = {|
color: Vec4,
color: Vec4
|};
/**
@ -149,11 +149,11 @@ type Clear = {|
*
*/
type Uniforms = {
[_: string]: mixed,
[_: string]: mixed
};
type UniformsOptions = {
[_: string]: ?$Shape<TextureOptions>,
[_: string]: ?$Shape<TextureOptions>
};
type Props = {|
@ -167,7 +167,7 @@ type Props = {|
backbuffering?: boolean,
blendFunc: BlendFuncSrcDst,
clear: ?Clear,
onDraw?: () => void,
onDraw?: () => void
|};
// not sure why, but we must define this for Flow to properly type check
@ -175,7 +175,7 @@ type DefaultProps = {
uniformsOptions: UniformsOptions,
uniforms: Uniforms,
blendFunc: BlendFuncSrcDst,
clear: ?Clear,
clear: ?Clear
};
type AsyncMixed = (redraw?: () => void) => mixed;
@ -240,7 +240,7 @@ type Framebuffer = {
color: WebGLTexture,
bind: () => void,
dispose: () => void,
syncSize: (w: number, h: number) => void,
syncSize: (w: number, h: number) => void
};
// minimal version of gl-fbo
@ -304,13 +304,13 @@ const createFBO = (
dispose: () => {
gl.deleteFramebuffer(handle);
gl.deleteTexture(color);
},
}
};
};
const defaultTextureOptions: TextureOptions = {
interpolation: "linear",
wrap: ["clamp to edge", "clamp to edge"],
wrap: ["clamp to edge", "clamp to edge"]
};
const applyTextureOptions = (
@ -355,7 +355,7 @@ const NodePropTypes = {
backbuffering: PropTypes.bool,
blendFunc: PropTypes.object,
clear: PropTypes.object,
onDraw: PropTypes.func,
onDraw: PropTypes.func
};
/**
@ -397,28 +397,28 @@ export default class Node extends Component {
blendFunc: {
// FIXME should this actually just be null by default? opt-in?
src: "src alpha",
dst: "one minus src alpha",
dst: "one minus src alpha"
},
clear: {
color: [0, 0, 0, 0],
},
color: [0, 0, 0, 0]
}
};
static contextTypes = {
glParent: PropTypes.object.isRequired,
glSurface: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired
};
static childContextTypes = {
glParent: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired
};
getChildContext() {
return {
glParent: this,
glSizable: this,
glSizable: this
};
}
@ -555,7 +555,7 @@ export default class Node extends Component {
// $FlowFixMe
const nextProps: Props = {
...this.drawProps,
...patch,
...patch
};
this._syncNextDrawProps(nextProps, this.context);
this.redraw();
@ -782,7 +782,7 @@ export default class Node extends Component {
shader: shaderProp,
blendFunc,
clear,
onDraw,
onDraw
} = this.drawProps;
//~ PREPARE phase
@ -850,7 +850,7 @@ export default class Node extends Component {
);
}
result = {
directTexture: this.getGLOutput(),
directTexture: this.getGLOutput()
};
} else if (obj instanceof Node) {
// maybe it's a Node?
@ -909,7 +909,7 @@ export default class Node extends Component {
initialObj,
obj,
dependency,
textureOptions,
textureOptions
});
const prepare = () => {
const texture: WebGLTexture =
@ -930,7 +930,7 @@ export default class Node extends Component {
};
return {
getMetaInfo,
prepare,
prepare
};
};
@ -955,7 +955,7 @@ export default class Node extends Component {
key,
type: uniformType,
getMetaInfo,
prepare,
prepare
};
} else if (Array.isArray(uniformType) && uniformType[0] === "sampler2D") {
let values;
@ -988,7 +988,7 @@ export default class Node extends Component {
type: uniformType,
getMetaInfo: () =>
all.reduce((acc, o) => acc.concat(o.getMetaInfo()), []),
prepare: () => all.map(o => o.prepare()),
prepare: () => all.map(o => o.prepare())
};
} else {
if (uniformValue === undefined) {
@ -997,7 +997,7 @@ export default class Node extends Component {
return {
key,
type: uniformType,
value: uniformValue,
value: uniformValue
};
}
};

View File

@ -13,7 +13,7 @@ const ShaderID = "ShaderID";
* }
*/
type ShaderDefinition = {|
frag: GLSLCode,
frag: GLSLCode
|};
export type { ShaderDefinition };
@ -23,13 +23,13 @@ export type { ShaderDefinition };
*/
type ShaderIdentifier = {
type: typeof ShaderID,
id: string,
id: string
};
export type { ShaderIdentifier };
type ShaderIdentifierMap<T> = {
[key: string]: T,
[key: string]: T
};
/**
@ -42,19 +42,19 @@ type ShaderIdentifierMap<T> = {
* }
*/
type ShadersDefinition = {
[key: string]: ShaderDefinition,
[key: string]: ShaderDefinition
};
/**
* An object map from a key string to a **ShaderIdentifier** that you can pass to `<Node shader>`
*/
type ShadersSheet<S: ShadersDefinition> = {
[key: $Keys<S>]: ShaderIdentifier,
[key: $Keys<S>]: ShaderIdentifier
};
type ShaderInfo = {
frag: GLSLCode,
vert: GLSLCode,
vert: GLSLCode
};
export type { ShaderInfo };
@ -98,7 +98,7 @@ export function shaderDefinitionToShaderInfo(
): ShaderInfo {
return {
frag: definition.frag,
vert: staticVert, // FIXME this is static for now. we will eventually improve this.
vert: staticVert // FIXME this is static for now. we will eventually improve this.
};
}
@ -157,6 +157,6 @@ const Shaders = {
shaderIdentifier.id
);
return shaderResults[shaderIdentifier.id];
},
}
};
export default Shaders;

View File

@ -43,7 +43,7 @@ export default class TextureLoader<T> {
// noop default implementation
return {
promise: new Promise(noop),
dispose: noop,
dispose: noop
};
}
}

View File

@ -27,7 +27,7 @@ const TextureLoaders = {
},
get() {
return loaderClasses;
},
}
};
export default TextureLoaders;

View File

@ -22,7 +22,7 @@ export type VisitorLike = {
deletions: Array<Node | Bus>
) => void,
+onNodeDraw: (node: Node, preparedUniforms: Array<*>) => void,
+onNodeDrawEnd: (node: Node) => void,
+onNodeDrawEnd: (node: Node) => void
};
/**

View File

@ -99,9 +99,10 @@ export default class VisitorLogger extends Visitor {
preparedUniforms.forEach(obj => {
let { key, type, value, getMetaInfo } = obj;
type = String(type || "UNKNOWN");
const values = value === undefined
? ""
: Array.isArray(value)
const values =
value === undefined
? ""
: Array.isArray(value)
? "[" + value.map(v => "`" + String(v) + "`").join(",") + "]"
: "`" + String(value) + "`";
let spaces = "";
@ -109,7 +110,9 @@ export default class VisitorLogger extends Visitor {
spaces += " ";
}
log(
`${spaces}*${type === "UNKNOWN" ? "[c='color:red']UNKNOWN[c]" : type}* _${key}_ = ${values}`,
`${spaces}*${type === "UNKNOWN"
? "[c='color:red']UNKNOWN[c]"
: type}* _${key}_ = ${values}`,
...(getMetaInfo ? aggregateInfo(getMetaInfo()) : [])
);
});

View File

@ -24,7 +24,7 @@ const Visitors = {
get() {
return _globalVisitors;
},
}
};
export default Visitors;

View File

@ -23,23 +23,23 @@ const connectSize = (
props: {
width?: number,
height?: number,
children?: any,
children?: any
};
context: {
glSizable: { +getGLSize: () => [number, number] },
glSizable: { +getGLSize: () => [number, number] }
};
static displayName = `connectSize(${GLComponent.displayName ||
GLComponent.name ||
"?"})`;
static propTypes = {
width: PropTypes.number,
height: PropTypes.number,
height: PropTypes.number
};
static contextTypes = {
glSizable: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired
};
static childContextTypes = {
glSizable: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired
};
getGLSize(): [number, number] {
const { props: { width, height }, context: { glSizable } } = this;
@ -49,7 +49,7 @@ const connectSize = (
}
getChildContext() {
return {
glSizable: this,
glSizable: this
};
}
component: ?GLComponent;

View File

@ -10,6 +10,6 @@ varying vec2 uv;
uniform sampler2D t;
void main(){
gl_FragColor=texture2D(t,uv);
}`,
},
}`
}
}).copy;

View File

@ -29,7 +29,7 @@ type SurfaceProps = {
onLoadError?: (e: Error) => void,
onContextLost?: () => void,
onContextRestored?: () => void,
visitor?: VisitorLike,
visitor?: VisitorLike
};
interface ISurface extends Component<void, SurfaceProps, any> {
@ -61,7 +61,7 @@ interface ISurface extends Component<void, SurfaceProps, any> {
+_getShader: (shaderId: ShaderIdentifier) => Shader,
+_makeShader: (shaderInfo: ShaderInfo) => Shader,
+_draw: () => void,
+_bindRootNode: () => void,
+_bindRootNode: () => void
}
export type Surface = ISurface;
@ -69,7 +69,7 @@ export type Surface = ISurface;
export type SurfaceContext = {
glParent: Node | Surface | Bus,
glSurface: Surface,
glSizable: { +getGLSize: () => [number, number] },
glSizable: { +getGLSize: () => [number, number] }
};
const SurfacePropTypes = {
@ -80,7 +80,7 @@ const SurfacePropTypes = {
onLoadError: PropTypes.func,
onContextLost: PropTypes.func,
onContextRestored: PropTypes.func,
visitor: PropTypes.object,
visitor: PropTypes.object
};
let surfaceId = 0;
@ -94,7 +94,7 @@ type SurfaceOpts = {
RenderLessElement: ReactClassLike<*>,
mapRenderableContent?: (instance: mixed) => mixed,
requestFrame: (f: Function) => number,
cancelFrame: (id: number) => void,
cancelFrame: (id: number) => void
};
export default ({
@ -103,7 +103,7 @@ export default ({
RenderLessElement,
mapRenderableContent,
requestFrame,
cancelFrame,
cancelFrame
}: SurfaceOpts): Class<ISurface> => {
/**
* **Renders the final tree of [Node](#node) in a WebGL Canvas / OpenGLView /...**
@ -172,11 +172,11 @@ export default ({
state: {
ready: boolean,
rebootId: number,
debug: boolean,
debug: boolean
} = {
ready: false,
rebootId: 0,
debug: false,
debug: false
};
RenderLessElement = RenderLessElement;
@ -186,14 +186,14 @@ export default ({
static childContextTypes: { [_: $Keys<SurfaceContext>]: any } = {
glSurface: PropTypes.object.isRequired,
glParent: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired,
glSizable: PropTypes.object.isRequired
};
getChildContext(): SurfaceContext {
return {
glParent: this,
glSurface: this,
glSizable: this,
glSizable: this
};
}
@ -250,7 +250,7 @@ export default ({
this.setState(({ rebootId }) => ({
rebootId: rebootId + 1,
ready: false,
debug: true,
debug: true
}));
}
@ -366,7 +366,7 @@ export default ({
const onSuccess = () => {
this.setState(
{
ready: true,
ready: true
},
() => {
try {

View File

@ -33,7 +33,7 @@ export {
TextureLoaders,
Visitor,
VisitorLogger,
Visitors,
Visitors
};
export type { Surface } from "./createSurface";

View File

@ -24,7 +24,7 @@ export function createComponent(
type UniformProps = {
children?: React.Element<*>,
name: string,
name: string
};
export class Uniform extends React.Component {
props: UniformProps;