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
S('CallExpression.objectType').each((objectType) => { | |
const obj = objectType.children('ObjectExpression'); | |
const nameString = obj.children('Property.name').children().eq(1).text(); | |
const definition = obj.children('Property.definition'); | |
const stringFunctions = definition.find('CallExpression.t.string'); | |
const refactoredStringFunctions = stringFunctions.map((fn) => { | |
const paramAsValue = fn.children().eq(1).text(); |
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
import { diffLines } from 'diff'; | |
import { writeFileSync } from 'fs'; | |
import { readFiles } from 'node-dir'; | |
import { format as prettierFormat } from 'prettier'; | |
import prettierTypescript from 'prettier/parser-typescript.js'; | |
import S from 'subsecond'; | |
const TARGET_DIR = '../src'; | |
const contents = []; |
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
S('MemberExpression').each((expression) => { | |
const [name, index] = expression.children().map((child) => child.text()); | |
const nameDotLength = `${name}.length`; | |
if (!index.startsWith(nameDotLength)) return; | |
expression.text(`${name}.at(${index.slice(nameDotLength.length)})`); | |
}); |
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
{ | |
"parser": "typescript", | |
"printWidth": 80, | |
"singleQuote": true, | |
"trailingComma": "es5", | |
"tabWidth": 2, | |
"useTabs": false, | |
"plugins": ["./prettier-plugin"] | |
} |
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
S('JSXOpeningElement').each((openingTag) => { | |
const attributeSortingGroups = []; | |
let currentAttributeGroup = []; | |
openingTag | |
.children('JSXAttribute, JSXSpreadAttribute') | |
.each((attribute, i) => { | |
if (attribute.type() === 'JSXSpreadAttribute') { | |
attributeSortingGroups.push(currentAttributeGroup.sort()); | |
currentAttributeGroup = []; |
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
const { parsers: typescriptParsers } = require('prettier/parser-typescript'); | |
const { parsers: javascriptParsers } = require('prettier/parser-babel'); | |
const S = require('subsecond'); | |
function preprocess(text, opts) { | |
S.load({ 'any.tsx': text }); | |
// A quick test to make sure everything works. | |
S().append('// its working!'); |
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
S('Program').each((file) => { | |
const imports = file | |
.children('ImportDeclaration') | |
.map((imp) => ({ | |
text: imp.text(), | |
hasNamedImports: imp.children().length !== 1, | |
packageName: imp.children('Literal').text(), | |
})) | |
.sort((a, b) => (a.packageName > b.packageName ? -1 : 1)); |
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
S('JSXOpeningElement').each((openingTag) => { | |
const attributes = openingTag.children('JSXAttribute'); | |
const sortedAttributes = attributes | |
.map((attribute) => attribute.text()) | |
.sort(); | |
attributes.each((attribute, i) => attribute.text(sortedAttributes[i])); | |
}); |
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
S('JSXOpeningElement.Button JSXAttribute.primary').text('type="primary"'); |
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
function __ss(){fetch("/checkout",{method:"POST"}).then((b,c)=>{if(c)throw c;if(b.url.includes("/cart"))return;let a=document.createElement("link");a.setAttribute("rel","prefetch"),a.setAttribute("href",b.url),a.setAttribute("id","_ss_pre"),document.head.append(a),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+b.url+"';")})})}__ss(),function(a,b){"function"==typeof b&&(a.fetch=function(){var c=b.apply(this,arguments);if(arguments[0].includes("cart")){let a=document.getElementById("_ss_pre");if(null==a)__ss();else{let d=a.getAttribute("href");a.setAttribute("href",""),setTimeout(()=>{a.setAttribute("href",d),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+d+"';")})},500)}}return c})}(window,window.fetch) |
NewerOlder