Skip to content

Commit

Permalink
Renamed variables/functions #5, renameVar('a_loopfilefullpath','A_Loo…
Browse files Browse the repository at this point in the history
…pFilePath')
  • Loading branch information
FuPeiJiang committed Jun 22, 2021
1 parent 97bae45 commit 7eca656
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions mocha/correct/Renamed variables.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v:=A_LoopFileFullPath
. A_LoopFileLongPath
. A_Clipboard
. A_ComSpec
1 change: 1 addition & 0 deletions mocha/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('toV2(text)',function() {
doItFiles('../tests3/listlines.ahk','correct/listlines.ah2')
doIt('SplitPath % ar[1],, Ou%t%Dir,,firstOutNameNoExt','SplitPath ar[1],, OutDir,,firstOutNameNoExt')
doItFiles('../tests3/v1assign with whiteSpace then nothing.ahk','correct/v1assign with whiteSpace then nothing.ah2')
doItFiles('../tests3/Renamed variables.ahk','correct/Renamed variables.ah2')
})

function toV2(text) {
Expand Down
15 changes: 15 additions & 0 deletions scripts/toLowerCase.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#SingleInstance force
SendMode "Input" ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.
#KeyHistory 0
ListLines 0

$f1::
{
send "^c"
sleep 100
A_Clipboard:=StrLower(A_Clipboard)
send "^v"
}

f3::Exitapp
5 changes: 3 additions & 2 deletions src/convertTov2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import ahkParser from './parser/index'
import modifyEverythingToV2 from './modifyEverythingToV2'

const content: Buffer =
fs.readFileSync('tests3/Legacy If var op value.ahk')
fs.readFileSync('tests3/v1assign with whiteSpace then nothing.ahk')
fs.readFileSync('tests3/Renamed variables.ahk')
// fs.readFileSync('tests3/Legacy If var op value.ahk')
// fs.readFileSync('tests3/v1assign with whiteSpace then nothing.ahk')
// fs.readFileSync('tov2/Base64Enc().ahk')
// fs.readFileSync('tests3/IfEqual_SameLineAction_mod.ahk')
// fs.readFileSync('mmikeww - AHK-v2-script-converter/input/ForcedExpression_Traditional_If_GreaterThanInt.ahk')
Expand Down
16 changes: 14 additions & 2 deletions src/modifyEverythingToV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export default (everything: ExtendedEverythingType): string => {
replaceReservedVar('case','dCase','_case')
replaceReservedVar('object','dObject','_object')
replaceReservedVar('array','dArray','_array')
replaceReservedVar('clipboard','A_Clipboard')
//https://www.autohotkey.com/v2/v2-changes.htm#built-in-variables
renameVar('a_loopfilefullpath','A_LoopFilePath')
renameVar('a_loopfilelongpath','A_LoopFileFullPath')
renameVar('clipboard','A_Clipboard')
renameVar('comspec','A_ComSpec')
const namesArr = Object.keys(varNames)
for (let n = 0,len = namesArr.length; n < len; n++) {
const thisName = namesArr[n]
Expand All @@ -101,6 +105,7 @@ export default (everything: ExtendedEverythingType): string => {
}
}
}
// theReservedVar should be lowercase
function replaceReservedVar(theReservedVar: string,firstChoice: string,subfixForAutoGen = '') {
const eIndexArr = lowerVarNames[theReservedVar]
if (eIndexArr) {
Expand All @@ -119,7 +124,14 @@ export default (everything: ExtendedEverythingType): string => {
}
}
}

function renameVar(varToRename: string,newName: string) {
const eIndexArr = lowerVarNames[varToRename]
if (eIndexArr) {
for (let n = 0,len = eIndexArr.length; n < len; n++) {
everything[eIndexArr[n]].text = newName
}
}
}

// https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript#1349426
function makeid(length: number) {
Expand Down
4 changes: 4 additions & 0 deletions tests3/Renamed variables.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
v:=A_LoopFilePath
. A_LoopFileFullPath
. A_Clipboard
. A_ComSpec

0 comments on commit 7eca656

Please sign in to comment.