-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial boilerplate for caniuse provider
- Loading branch information
Showing
668 changed files
with
208 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 Amila Welihinda | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// @flow | ||
import { rules } from './providers/index'; | ||
|
||
|
||
// @HACK: This is just for testing purposes. Its used to mimic the actual | ||
// 'polyfill' property that will eventually be user configurable. Its | ||
// hardcoded for now | ||
const tempPolyfills = new Set(['typed-array']); | ||
|
||
export type Targets = string[]; | ||
|
||
export type ESLintNode = { | ||
type: string, | ||
callee: { | ||
type: string, | ||
computed: bool, | ||
object: { | ||
type: string, | ||
name: string | ||
}, | ||
property: { | ||
type: string, | ||
name: string | ||
} | ||
} | ||
} | ||
|
||
export type Node = { | ||
ASTNodeType: string, | ||
id: string, | ||
object: string, | ||
property: string, | ||
isValid: (node: Object, eslintNode: ESLintNode) => bool; | ||
} | ||
|
||
/** | ||
* Check if the feature is supported | ||
*/ | ||
function DetermineCompat(node: ESLintNode, polyfills: Set<string>, targets: string[]): bool { | ||
// Given the AST, find all the matching AST nodes and validate each one | ||
|
||
} | ||
|
||
/** | ||
* Return false if a if a rule fails | ||
*/ | ||
function Validate(node: ESLintNode): bool { | ||
// Find the corresponding rules for a node by it's ASTNodeType | ||
return rules | ||
.filter((rule: Node): bool => | ||
// Validate ASTNodeType | ||
rule.ASTNodeType !== node.type && | ||
// Check if polyfill is provided | ||
!tempPolyfills.has(rule.id) | ||
) | ||
.some((rule: Node): bool => rule.isValid(node, node)); | ||
} | ||
|
||
export default DetermineCompat; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
// @flow | ||
type node = { | ||
ASTNodeType: string, | ||
object: string, | ||
property: string | ||
} | ||
import { readFileSync } from 'fs'; | ||
import type { Node, ESLintNode, Targets } from '../DetermineCompat'; | ||
|
||
|
||
export const supportedTargets: Targets = [ | ||
'chrome', 'firefox', 'opera', 'safari', 'android', 'ie', 'edge', | ||
'ios_saf', 'op_mini', 'android', 'bb', 'op_mob', 'and_chr', 'and_ff', | ||
'ie_mob', 'and_uc', 'samsung' | ||
]; | ||
|
||
function isValid(node: Node, eslintNode: ESLintNode, targets: Targets): bool { | ||
// Filter non-matching objects and properties | ||
if ( | ||
!eslintNode.callee.object.name === node.object || | ||
!eslintNode.callee.property.name === node.property | ||
) return false; | ||
|
||
export function Provider(_node: node): bool { | ||
// Check if polyfill is provided | ||
global.doo = _node.object + {}; | ||
// Check the CanIUse database to see if targets are supported | ||
const caniuseRecord: Object = JSON.parse( | ||
readFileSync(`./caniuse/features-json/${node.id}.json`).toString() | ||
).stats; | ||
|
||
// Check if targets are supported. By default, get the latest version of each | ||
// target environment | ||
return targets.some((target: Object): bool => { | ||
const versions = Object.values(caniuseRecord[target]); | ||
const latest = versions[versions.length - 1]; | ||
return latest !== 'n'; | ||
}); | ||
} | ||
|
||
export default { | ||
'typed-array': { | ||
const CanIUseProvider: Node[] = [ | ||
// ex. Float32Array() | ||
{ | ||
id: 'typed-array', | ||
ASTNodeType: 'CallExpression', | ||
object: 'document', | ||
property: 'ServiceWorker' | ||
property: 'ServiceWorker', | ||
isValid | ||
}, | ||
'document-queryselector': { | ||
// ex. document.querySelector() | ||
{ | ||
id: 'query-selector', | ||
ASTNodeType: 'CallExpression', | ||
global: 'document', | ||
property: 'querySelector' | ||
object: 'document', | ||
property: 'querySelector', | ||
isValid | ||
} | ||
}; | ||
]; | ||
|
||
export default CanIUseProvider; |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.